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 27, 2021
1 parent c560c3b commit 523a344
Show file tree
Hide file tree
Showing 2 changed files with 39 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,10 @@ 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 +70,12 @@ 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') === true) {
$io->note(sprintf('Would have sent the command "%s %s", skipping', $requestConfiguration->getMethod(), $requestConfiguration->getEndpoint()));
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
47 changes: 29 additions & 18 deletions src/Command/Extension/SetExtensionVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ 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 +59,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

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

$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 +69,15 @@ 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;
}
} else {
$io->note(sprintf('Would have set version in ext_emconf.php to %s, skipping', $version));
}

if ($input->getOption('no-docs') === null
Expand All @@ -90,18 +97,22 @@ 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;
}
} else {
$io->note(sprintf('Would have set version in Documentation/Settings.cfg to %s, skipping', $version));
}

return 0;
Expand Down

0 comments on commit 523a344

Please sign in to comment.