Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Introduce --dry-run option to commands #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should output the command name instead, not sure....

return 0;
gilbertsoft marked this conversation as resolved.
Show resolved Hide resolved
}

// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just do an early return above L:71? There is nothing to do below, in case this is a dry run. Would make the change a bit smaller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a note here and below. If we like to keep this output, no.

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