From 997ef5989e3ecb4e2775c5d7cb51f2f129b06b64 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Thu, 26 May 2022 20:27:17 +0300 Subject: [PATCH] Added flag to inverse servers-filter logic. --- src/Commands/Servers/ViewCommand.php | 19 ++++++------------- src/Commands/State/ExportCommand.php | 3 ++- src/Commands/State/ImportCommand.php | 3 ++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Commands/Servers/ViewCommand.php b/src/Commands/Servers/ViewCommand.php index 0a63fc31..25d8e263 100644 --- a/src/Commands/Servers/ViewCommand.php +++ b/src/Commands/Servers/ViewCommand.php @@ -24,13 +24,8 @@ final class ViewCommand extends Command { $this->setName('servers:view') ->setDescription('View Servers settings.') - ->addOption( - 'servers-filter', - 's', - InputOption::VALUE_OPTIONAL, - 'View selected servers, comma seperated. \'s1,s2\'.', - '' - ) + ->addOption('servers-filter', 's', InputOption::VALUE_OPTIONAL, 'Select backends. Comma (,) seperated.', '') + ->addOption('exclude', null, InputOption::VALUE_NONE, 'Inverse --servers-filter logic.') ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Use Alternative config file.') ->addArgument( 'filter', @@ -61,13 +56,11 @@ final class ViewCommand extends Command $filter = $input->getArgument('filter'); foreach (Config::get('servers', []) as $serverName => $server) { - if ($isCustom && !in_array($serverName, $selected, true)) { + + if ($isCustom && $input->getOption('exclude') === in_array($serverName, $selected)) { $output->writeln( - sprintf( - 'Ignoring \'%s\' as requested by [-s, --servers-filter] flag.', - $serverName - ), - OutputInterface::VERBOSITY_DEBUG + sprintf('%s: Ignoring backend as requested by [-s, --servers-filter].', $serverName), + OutputInterface::VERBOSITY_VERY_VERBOSE ); continue; } diff --git a/src/Commands/State/ExportCommand.php b/src/Commands/State/ExportCommand.php index 4c9ae984..a6cc7762 100644 --- a/src/Commands/State/ExportCommand.php +++ b/src/Commands/State/ExportCommand.php @@ -48,6 +48,7 @@ class ExportCommand extends Command ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not commit any changes.') ->addOption('timeout', null, InputOption::VALUE_REQUIRED, 'Set request timeout in seconds.') ->addOption('servers-filter', 's', InputOption::VALUE_OPTIONAL, 'Select backends. Comma (,) seperated.', '') + ->addOption('exclude', null, InputOption::VALUE_NONE, 'Inverse --servers-filter logic.') ->addOption('ignore-date', 'i', InputOption::VALUE_NONE, 'Ignore date comparison.') ->addOption('trace', null, InputOption::VALUE_NONE, 'Enable Debug Tracing mode.') ->addOption( @@ -93,7 +94,7 @@ class ExportCommand extends Command foreach (Config::get('servers', []) as $name => $backend) { $type = strtolower(ag($backend, 'type', 'unknown')); - if ($isCustom && false === in_array($name, $selected)) { + if ($isCustom && $input->getOption('exclude') === in_array($name, $selected)) { $this->logger->info( sprintf('%s: Ignoring backend as requested by [-s, --servers-filter].', $name) ); diff --git a/src/Commands/State/ImportCommand.php b/src/Commands/State/ImportCommand.php index 0bbcebe4..f0025319 100644 --- a/src/Commands/State/ImportCommand.php +++ b/src/Commands/State/ImportCommand.php @@ -45,6 +45,7 @@ class ImportCommand extends Command ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not commit any changes.') ->addOption('timeout', null, InputOption::VALUE_REQUIRED, 'Set request timeout in seconds.') ->addOption('servers-filter', 's', InputOption::VALUE_OPTIONAL, 'Select backends. Comma (,) seperated.', '') + ->addOption('exclude', null, InputOption::VALUE_NONE, 'Inverse --servers-filter logic.') ->addOption('trace', null, InputOption::VALUE_NONE, 'Enable Debug Tracing mode.') ->addOption( 'always-update-metadata', @@ -103,7 +104,7 @@ class ImportCommand extends Command foreach (Config::get('servers', []) as $serverName => $server) { $type = strtolower(ag($server, 'type', 'unknown')); - if ($isCustom && !in_array($serverName, $selected, true)) { + if ($isCustom && $input->getOption('exclude') === in_array($serverName, $selected)) { $this->logger->info( sprintf('%s: Ignoring backend as requested by [-s, --servers-filter].', $serverName) );