From 3949b850c5d287ef97a907af3cd8ef2739b9a09a Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 20 Aug 2024 13:00:13 +0300 Subject: [PATCH] Converted "--deploy" option of the `commit`/`update` commands into "--auto-deploy yes/no" option --- CHANGELOG.md | 6 ++- README.md | 4 +- src/SVNBuddy/Command/CommitCommand.php | 36 ++++++++++--- src/SVNBuddy/Command/UpdateCommand.php | 75 +++++++++++++++++++++++--- 4 files changed, 102 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ca0f2..0c7bf43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Display non-executed SVN command (results pulled from the cache) in the verbose mode. - Display non-executed SVN command (results pulled from the cache) results in the debug mode. - Added the `deploy` command, that will execute, specified in the config, local/remote commands. -- Added `--deploy` option to the `commit` command, that will perform a remote deployment after a successful commit (#131). -- Added `--deploy` option to the `update` command, that will perform a local deployment after a successful update. +- Added `commit.auto-deploy` config setting (enabled by default), that allows to tell if a remote deployment should happen after successful commit (#131). +- Added `--auto-deploy` option to `commit` command to allow overriding behavior imposed by `commit.auto-deploy` config setting. +- Added `update.auto-deploy` config setting (enabled by default), that allows to tell if a local deployment should happen after successful update. +- Added `--auto-deploy` option to `update` command to allow overriding behavior imposed by `update.auto-deploy` config setting. ### Changed - The `config` command groups configuration settings by a command. diff --git a/README.md b/README.md index f06ecf9..ecd3631 100755 --- a/README.md +++ b/README.md @@ -452,7 +452,7 @@ The command sends changes from your working copy to the repository. * `--cl` - Operate only on members of selected changelist * `--merge-template=MERGE-TEMPLATE` Use alternative merge template for this commit -* `-d`, `--deploy` - Perform remote deployment after a successful commit +* `--auto-deploy=AUTO-DEPLOY` - Automatically perform remote deployment on successful commit, e.g. `yes` or `no` #### Configuration settings @@ -563,7 +563,7 @@ Bring changes from the repository into the working copy. * `-r`, `--revision=REVISION` - Update working copy to specified revision, e.g. `NUMBER`, `{DATE}`, `HEAD`, `BASE`, `COMMITTED`, `PREV` * `--ignore-externals` - Ignore externals definitions -* `-d`, `--deploy` - Perform local deployment after a successful update +* `--auto-deploy=AUTO-DEPLOY` - Automatically perform local deployment on successful update, e.g. `yes` or `no` #### Examples diff --git a/src/SVNBuddy/Command/CommitCommand.php b/src/SVNBuddy/Command/CommitCommand.php index b288315..fc8f652 100644 --- a/src/SVNBuddy/Command/CommitCommand.php +++ b/src/SVNBuddy/Command/CommitCommand.php @@ -30,6 +30,8 @@ class CommitCommand extends AbstractCommand implements IConfigAwareCommand const SETTING_COMMIT_MERGE_TEMPLATE = 'commit.merge-template'; + const SETTING_COMMIT_AUTO_DEPLOY = 'commit.auto-deploy'; + const STOP_LINE = '--This line, and those below, will be ignored--'; /** @@ -90,10 +92,10 @@ protected function configure() 'Use alternative merge template for this commit' ) ->addOption( - 'deploy', - 'd', - InputOption::VALUE_NONE, - 'Perform remote deployment after a successful commit' + 'auto-deploy', + null, + InputOption::VALUE_REQUIRED, + 'Automatically perform remote deployment on successful commit, e.g. yes or no' ); parent::configure(); @@ -115,6 +117,10 @@ public function completeOptionValues($optionName, CompletionContext $context) return $this->getMergeTemplateNames(); } + if ( $optionName === 'auto-deploy' ) { + return array('yes', 'no'); + } + return $ret; } @@ -222,13 +228,22 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function deploy() { - if ( !$this->io->getOption('deploy') ) { - return false; + $auto_deploy = $this->io->getOption('auto-deploy'); + + if ( $auto_deploy !== null ) { + $auto_deploy = $auto_deploy === 'yes'; } + else { + $auto_deploy = (boolean)$this->getSetting(self::SETTING_COMMIT_AUTO_DEPLOY); + } + + if ( $auto_deploy ) { + $this->runOtherCommand('deploy', array('--remote' => true)); - $this->runOtherCommand('deploy', array('--remote' => true)); + return true; + } - return true; + return false; } /** @@ -311,6 +326,11 @@ public function getConfigSettings() $merge_template_names, reset($merge_template_names) ), + new ChoiceConfigSetting( + self::SETTING_COMMIT_AUTO_DEPLOY, + array(1 => 'Yes', 0 => 'No'), + 1 + ), ); } diff --git a/src/SVNBuddy/Command/UpdateCommand.php b/src/SVNBuddy/Command/UpdateCommand.php index 0845cb0..a28bb74 100644 --- a/src/SVNBuddy/Command/UpdateCommand.php +++ b/src/SVNBuddy/Command/UpdateCommand.php @@ -11,15 +11,20 @@ namespace ConsoleHelpers\SVNBuddy\Command; +use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; +use ConsoleHelpers\SVNBuddy\Config\ChoiceConfigSetting; use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyConflictTracker; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class UpdateCommand extends AbstractCommand implements IAggregatorAwareCommand +class UpdateCommand extends AbstractCommand implements IAggregatorAwareCommand, IConfigAwareCommand { + const SETTING_UPDATE_AUTO_DEPLOY = 'update.auto-deploy'; + /** * Working copy conflict tracker. * @@ -69,15 +74,34 @@ protected function configure() 'Ignore externals definitions' ) ->addOption( - 'deploy', - 'd', - InputOption::VALUE_NONE, - 'Perform local deployment after a successful update' + 'auto-deploy', + null, + InputOption::VALUE_REQUIRED, + 'Automatically perform local deployment on successful update, e.g. yes or no' ); parent::configure(); } + /** + * Return possible values for the named option + * + * @param string $optionName Option name. + * @param CompletionContext $context Completion context. + * + * @return array + */ + public function completeOptionValues($optionName, CompletionContext $context) + { + $ret = parent::completeOptionValues($optionName, $context); + + if ( $optionName === 'auto-deploy' ) { + return array('yes', 'no'); + } + + return $ret; + } + /** * {@inheritdoc} */ @@ -115,9 +139,30 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->io->writeln('Done'); - if ( $this->io->getOption('deploy') ) { - $this->runOtherCommand('deploy', array('--local' => true)); + $this->deploy(); + } + + /** + * Performs a deploy. + * + * @return void + */ + protected function deploy() + { + $auto_deploy = $this->io->getOption('auto-deploy'); + + if ( $auto_deploy !== null ) { + $auto_deploy = $auto_deploy === 'yes'; + } + else { + $auto_deploy = (boolean)$this->getSetting(self::SETTING_UPDATE_AUTO_DEPLOY); + } + + if ( !$auto_deploy ) { + return; } + + $this->runOtherCommand('deploy', array('--local' => true)); } /** @@ -130,4 +175,20 @@ public function getAggregatedOptions() return array('ignore-externals'); } + /** + * Returns list of config settings. + * + * @return AbstractConfigSetting[] + */ + public function getConfigSettings() + { + return array( + new ChoiceConfigSetting( + self::SETTING_UPDATE_AUTO_DEPLOY, + array(1 => 'Yes', 0 => 'No'), + 1 + ), + ); + } + }