Skip to content

Commit

Permalink
[FEATURE] Introduce --dry-run option to commands
Browse files Browse the repository at this point in the history
Resolves #40
  • Loading branch information
gilbertsoft committed Nov 17, 2021
1 parent c560c3b commit 3f2af41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
12 changes: 10 additions & 2 deletions src/Command/AbstractClientRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ abstract class AbstractClientRequestCommand extends Command

protected function configure(): void
{
// General option to get a raw result. Can be used for further processing.
$this->addOption('raw', 'r', InputOption::VALUE_OPTIONAL, 'Return result as raw object (e.g. json)', false);
$this
// General option to get a raw result. Can be used for further processing.
->addOption('raw', 'r', InputOption::VALUE_OPTIONAL, 'Return result as raw object (e.g. json)', false)
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -68,6 +71,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->setRaw($input->getOption('raw') !== false)
->setDefaultAuthMethod($this->defaultAuthMethod);

// In case of a dry-run the request to TER is skipped.
if ($input->getOption('dry-run') !== false) {
return 0;
}

// RequestService returns a boolean for whether the request was successful or not.
// Since we have to return an exit code, this must be negated and casted to return
// 0 on success and 1 on failure.
Expand Down
44 changes: 26 additions & 18 deletions src/Command/Extension/SetExtensionVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ protected function configure(): void
->setDescription('Update the extensions ext_emconf.php version to a specific version. Useful in CI environments')
->addArgument('version', InputArgument::REQUIRED, 'The version to publish, e.g. 1.2.3. Must have three digits.')
->addOption('path', '', InputOption::VALUE_OPTIONAL, 'Path to the extension folder', getcwd() ?: './')
->addOption('no-docs', '', InputOption::VALUE_OPTIONAL, 'Disable version update in documentation settings', false);
->addOption('no-docs', '', InputOption::VALUE_OPTIONAL, 'Disable version update in documentation settings', false)
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -58,6 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$dryRun = ($input->getOption('dry-run') !== false);

$emConfFile = rtrim($path, '/') . '/ext_emconf.php';
if (!file_exists($emConfFile)) {
$io->error(sprintf('No \'ext_emconf.php\' found in the given path %s.', $path));
Expand All @@ -66,11 +70,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$versionReplacer = new VersionReplacer($version);

try {
$versionReplacer->setVersion($emConfFile, self::EMCONF_PATTERN);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while setting the ext_emconf.php version to %s.', $version));
return 1;
if ($dryRun) {
try {
$versionReplacer->setVersion($emConfFile, self::EMCONF_PATTERN);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while setting the ext_emconf.php version to %s.', $version));
return 1;
}
}

if ($input->getOption('no-docs') === null
Expand All @@ -90,18 +96,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

try {
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_RELEASE_PATTERN);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while updating the release number in %s', $documentationSettingsFile));
return 1;
}

try {
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_VERSION_PATTERN, 2);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while updating the version number in %s', $documentationSettingsFile));
return 1;
if ($dryRun) {
try {
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_RELEASE_PATTERN);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while updating the release number in %s', $documentationSettingsFile));
return 1;
}

try {
$versionReplacer->setVersion($documentationSettingsFile, self::DOCUMENTATION_VERSION_PATTERN, 2);
} catch (\InvalidArgumentException $e) {
$io->error(sprintf('An error occurred while updating the version number in %s', $documentationSettingsFile));
return 1;
}
}

return 0;
Expand Down

0 comments on commit 3f2af41

Please sign in to comment.