Skip to content

Commit

Permalink
Add successful exit code to all commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
ygerasimov committed Feb 11, 2025
1 parent b287517 commit f80838b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Commands/AuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Diffy\Diffy;
use DiffyCli\Config;
use Robo\ResultData;
use Robo\Tasks;

class AuthCommand extends Tasks
Expand All @@ -25,5 +26,8 @@ public function logIn($apiKey)

Config::saveApiKey($apiKey);
$this->io()->success("Key is validated and saved");

// Successful exit.
return new ResultData();
}
}
10 changes: 10 additions & 0 deletions src/Commands/BrowserStackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use DiffyCli\Config;
use DiffyCli\BrowserStack;
use Exception;
use Robo\ResultData;
use Robo\Tasks;

class BrowserStackCommand extends Tasks
Expand All @@ -35,6 +36,9 @@ public function saveBrowserStackCredentials($username, $accessKey)
{
Config::saveBrowserstackCredentials($username, $accessKey);
$this->io()->success('Browserstack username and access key saved');

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -63,6 +67,9 @@ public function browserKeysList()
}

$this->io()->table($headers, $rows);

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -187,6 +194,9 @@ function ($url) use ($baseUrl, $production) {
$screenshotId = Screenshot::createBrowserStackScreenshot($projectId, $screenshotResults);
$screenshotLink = rtrim(Diffy::$uiBaseUrl, '/') . '/snapshots/' . $screenshotId;
$this->io()->success('Screenshot was successfully created. Screenshot: ' . $screenshotLink);

// Successful exit.
return new ResultData();
}

/**
Expand Down
18 changes: 17 additions & 1 deletion src/Commands/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Diffy\InvalidArgumentsException;
use DiffyCli\Config;
use N98\JUnitXml\Document;
use Robo\ResultData;
use Robo\Tasks;

class DiffCommand extends Tasks
Expand Down Expand Up @@ -64,6 +65,9 @@ public function createDiff(
}

$this->io()->write($diffId);

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -86,6 +90,9 @@ public function getDiffStatus(int $diffId)
$diff = Diff::retrieve($diffId);

$this->io()->write($diff->isCompleted());

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -108,6 +115,9 @@ public function getDiffPercent(int $diffId)
$diff = Diff::retrieve($diffId);

$this->io()->write($diff->getChangesPercentage());

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -125,7 +135,7 @@ public function getDiffPercent(int $diffId)
*
* @usage diff:get-result 12345 --format=junit-xml Get diff result.
*/
public function getDiffResult(int $diffId, array $options = ['format' => '']): void
public function getDiffResult(int $diffId, array $options = ['format' => ''])
{
$format = $options['format'] ?? '';

Expand Down Expand Up @@ -198,6 +208,9 @@ public function getDiffResult(int $diffId, array $options = ['format' => '']): v
$rootElement->setAttribute('skipped', 0);

$this->io()->write($document->saveXML());

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -246,5 +259,8 @@ public function getDiffs(int $projectId, $page = 0)
['Total pages' => $totalPages],
['Current page' => $page]
);

// Successful exit.
return new ResultData();
}
}
10 changes: 10 additions & 0 deletions src/Commands/LambdaTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use DiffyCli\Config;
use DiffyCli\LambdaTest;
use Exception;
use Robo\ResultData;
use Robo\Tasks;

/**
Expand Down Expand Up @@ -43,6 +44,9 @@ public function saveLambdaTestCredentials($username, $accessToken)
{
Config::saveLambdaTestCredentials($username, $accessToken);
$this->io()->success('LambdaTest username and access token saved');

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -68,6 +72,9 @@ public function browserKeysList()
}

$this->io()->table($headers, $rows);

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -191,6 +198,9 @@ function ($url) use ($baseUrl, $production) {
$screenshotId = Screenshot::createBrowserStackScreenshot($projectId, $screenshotResults);
$screenshotLink = rtrim(Diffy::$uiBaseUrl, '/') . '/snapshots/' . $screenshotId;
$this->io()->success('Screenshot was successfully created. Screenshot: ' . $screenshotLink);

// Successful exit.
return new ResultData();
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Commands/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use DiffyCli\Config;
use GuzzleHttp\Exception\InvalidArgumentException;
use GuzzleHttp\Utils;
use Robo\ResultData;
use Robo\Tasks;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -172,6 +173,9 @@ public function createCompare(
}

$this->getIO()->writeln($diffId);

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -196,6 +200,9 @@ public function updateProject(int $projectId, string $configurationPath)
}

$this->getIO()->writeln('Project <info>' . $projectId . '</info> updated.');

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -221,6 +228,9 @@ public function updateProjects(string $configurationPath)
$this->getIO()->writeln('Project <info>' . $projectId . '</info> updated.');
}
}

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -250,6 +260,9 @@ public function createProject(string $configurationPath)
$project_id = Project::createFromData($configuration);
$this->getIO()->writeln('[<info>' . $project_id . '</info>] <comment>' . $configuration['name'] . '</comment> created.');
}

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -271,6 +284,9 @@ public function getProject(int $projectId)
$project = Project::get($projectId);

$this->getIO()->writeln(json_encode($project));

// Successful exit.
return new ResultData();
}

protected function getIO(): SymfonyStyle
Expand Down
16 changes: 15 additions & 1 deletion src/Commands/ScreenshotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Diffy\Screenshot;
use DiffyCli\Config;
use GuzzleHttp\Exception\InvalidArgumentException;
use Robo\ResultData;
use Robo\Tasks;

use function GuzzleHttp\json_decode;
Expand Down Expand Up @@ -80,7 +81,8 @@ public function createScreenshot($projectId, $environment, array $options = ['wa

$this->io()->write($screenshotId);

return $screenshotId;
// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -128,6 +130,9 @@ public function listScreenshot($projectId, array $options = ['name' => '', 'limi
}

$this->io()->write(var_export($screenshots, true));

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -164,6 +169,9 @@ public function createScreenshotUpload($projectId, string $configurationPath)
$screenshotId = Screenshot::createUpload($projectId, $configuration);

$this->io()->write($screenshotId);

// Successful exit.
return new ResultData();
}

/**
Expand Down Expand Up @@ -192,6 +200,9 @@ public function createScreenshotBaseline($projectId, $environment, array $option

$screenshotId = $this->createScreenshot($projectId, $environment, $options);
Screenshot::setBaselineSet($projectId, $screenshotId);

// Successful exit.
return new ResultData();
}

/**
Expand All @@ -212,5 +223,8 @@ public function setScreenshotBaseline($projectId, $screenshotId)

Screenshot::setBaselineSet($projectId, $screenshotId);
$this->io()->write(sprintf('Baseline for project %d has been updated.', $projectId));

// Successful exit.
return new ResultData();
}
}

0 comments on commit f80838b

Please sign in to comment.