Adds an argument.
public addArgument ( string $name, integer $mode = null, string $description = '', mixed $default = null ) : |
||
$name | string | The argument name |
$mode | integer | The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL |
$description | string | A description text |
$default | mixed | The default value (for InputArgument::OPTIONAL mode only) |
Результат | The current instance |
/** * {@inheritdoc} */ public function configure(Command $command) { $locatorsExamples = implode(PHP_EOL, array_map(function ($locator) { return '- ' . $locator; }, $this->specificationFinder->getExampleLocators())); $command->addArgument('paths', InputArgument::OPTIONAL, 'Optional path(s) to execute. Could be:' . PHP_EOL . $locatorsExamples)->addOption('--dry-run', null, InputOption::VALUE_NONE, 'Invokes formatters without executing the tests and hooks.'); }
public function createCommand(TaskInfo $taskInfo) { $task = new Command($taskInfo->getName()); $task->setDescription($taskInfo->getDescription()); $task->setHelp($taskInfo->getHelp()); $args = $taskInfo->getArguments(); foreach ($args as $name => $val) { $description = $taskInfo->getArgumentDescription($name); if ($val === TaskInfo::PARAM_IS_REQUIRED) { $task->addArgument($name, InputArgument::REQUIRED, $description); } elseif (is_array($val)) { $task->addArgument($name, InputArgument::IS_ARRAY, $description, $val); } else { $task->addArgument($name, InputArgument::OPTIONAL, $description, $val); } } $opts = $taskInfo->getOptions(); foreach ($opts as $name => $val) { $description = $taskInfo->getOptionDescription($name); $fullName = $name; $shortcut = ''; if (strpos($name, '|')) { list($fullName, $shortcut) = explode('|', $name, 2); } if (is_bool($val)) { $task->addOption($fullName, $shortcut, InputOption::VALUE_NONE, $description); } else { $task->addOption($fullName, $shortcut, InputOption::VALUE_OPTIONAL, $description, $val); } } return $task; }
public static function configure(Command $command) { $command->addArgument('path', InputArgument::OPTIONAL, 'Path to benchmark(s)'); $command->addOption('filter', array(), InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore all benchmarks not matching command filter (can be a regex)'); $command->addOption('group', array(), InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Group to run (can be specified multiple times)'); $command->addOption('parameters', null, InputOption::VALUE_REQUIRED, 'Override parameters to use in (all) benchmarks'); $command->addOption('revs', null, InputOption::VALUE_REQUIRED, 'Override number of revs (revolutions) on (all) benchmarks'); $command->addOption('progress', 'l', InputOption::VALUE_REQUIRED, 'Progress logger to use, one of <comment>dots</comment>, <comment>classdots</comment>'); // command option is parsed before the container is compiled. $command->addOption('bootstrap', 'b', InputOption::VALUE_REQUIRED, 'Set or override the bootstrap file.'); $command->addOption('group', array(), InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Group to run (can be specified multiple times)'); $command->addOption('executor', array(), InputOption::VALUE_REQUIRED, 'Executor to use', 'microtime'); }
public static function configure(Command $command) { $command->addArgument('path', InputArgument::OPTIONAL, 'Path to benchmark(s)'); $command->addOption('filter', [], InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore all benchmarks not matching command filter (can be a regex)'); $command->addOption('group', [], InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Group to run (can be specified multiple times)'); $command->addOption('parameters', null, InputOption::VALUE_REQUIRED, 'Override parameters to use in (all) benchmarks'); $command->addOption('revs', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Override number of revs (revolutions) on (all) benchmarks'); $command->addOption('progress', 'l', InputOption::VALUE_REQUIRED, 'Progress logger to use, one of <comment>dots</comment>, <comment>classdots</comment>'); // command option is parsed before the container is compiled. $command->addOption('bootstrap', 'b', InputOption::VALUE_REQUIRED, 'Set or override the bootstrap file.'); $command->addOption('group', [], InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Group to run (can be specified multiple times)'); $command->addOption('executor', [], InputOption::VALUE_REQUIRED, 'Executor to use', 'microtime'); $command->addOption('stop-on-error', [], InputOption::VALUE_NONE, 'Stop on the first error encountered.'); // Launcher options (processed in PhpBench.php before the container is initialized). $command->addOption('php-binary', null, InputOption::VALUE_REQUIRED, 'Alternative PHP binary to use'); $command->addOption('php-config', null, InputOption::VALUE_REQUIRED, 'JSON-like object of PHP INI settings'); $command->addOption('php-wrapper', null, InputOption::VALUE_REQUIRED, 'Prefix process launch command with this string'); }
/** * @param $className * @param TaskInfo $taskInfo * @return Command */ protected function createCommand($className, TaskInfo $taskInfo) { if ($className === strtolower(Tg::TGCLASS)) { $name = $taskInfo->getName(); } else { $camel = preg_replace("/:/", '-', $taskInfo->getName()); $name = $className . ':' . $camel; } $task = new Command($name); $task->setDescription($taskInfo->getDescription()); $task->setHelp($taskInfo->getHelp()); $args = $taskInfo->getArguments(); foreach ($args as $name => $val) { $description = $taskInfo->getArgumentDescription($name); if ($val === TaskInfo::PARAM_IS_REQUIRED) { $task->addArgument($name, InputArgument::REQUIRED, $description); } elseif (is_array($val)) { $task->addArgument($name, InputArgument::IS_ARRAY, $description, $val); } else { $task->addArgument($name, InputArgument::OPTIONAL, $description, $val); } } $opts = $taskInfo->getOptions(); foreach ($opts as $name => $val) { $description = $taskInfo->getOptionDescription($name); $fullName = $name; $shortcut = ''; if (strpos($name, '|')) { list($fullName, $shortcut) = explode('|', $name, 2); } if (is_bool($val)) { $task->addOption($fullName, $shortcut, InputOption::VALUE_NONE, $description); } else { $task->addOption($fullName, $shortcut, InputOption::VALUE_OPTIONAL, $description, $val); } } return $task; }
/** * {@inheritdoc} */ public function addArgument($name, $mode = null, $description = '', $default = null) { $this->decoratedCommand->addArgument($name, $mode, $description, $default); return $this; }
/** * {@inheritdoc} */ public function configure(Command $command) { $command->addArgument(self::ARG_FILE, InputArgument::OPTIONAL, 'Load tests from a specific file or path.'); }
public function addArgument($name, $mode = null, $description = '', $default = null) { return $this->innerCommand->addArgument($name, $mode, $description, $default); }
/** * Configures command to be able to process it later. * * @param Command $command */ public function configure(Command $command) { $command->addArgument('features', InputArgument::OPTIONAL, "Feature(s) to run. Could be:" . "\n- a dir (<comment>src/to/Bundle/Features/</comment>), " . "\n- a feature (<comment>src/to/Bundle/Features/*.feature</comment>), " . "\n- a scenario at specific line (<comment>src/to/Bundle/Features/*.feature:10</comment>). " . "\n- Also, you can use short bundle notation (<comment>@BundleName/*.feature:10</comment>)"); }
/** * @see Symfony\Component\Console\Command::addArgument This method is a proxy * * @return BuildStep */ protected function addArgument(string $name, int $mode = null, string $description = '', $default = null) { $this->command->addArgument($name, $mode, $description, $default); return $this; }
/** * Add an argument to the command * * @return BaseCommand * @author Dan Cox */ public function argument($name, $description, $required = 'required') { $argVal = array_key_exists($required, $this->argumentValueConstants) ? $this->argumentValueConstants[$required] : $required; parent::addArgument($name, $argVal, $description); return $this; }
/** * Configures command to be able to process it later. * * @param Command $command */ public function configure(Command $command) { $command->addArgument('features', InputArgument::OPTIONAL, "Feature(s) to run. Could be:\n" . "- a dir <comment>(features/)</comment>\n" . "- a feature <comment>(*.feature)</comment>\n" . "- a scenario at specific line <comment>(*.feature:10)</comment>.\n" . "- all scenarios at or after a specific line <comment>(*.feature:10-*)</comment>.\n" . "- all scenarios at a line within a specific range <comment>(*.feature:10-20)</comment>."); }
public function configure(Command $command) { $command->addArgument('features', InputArgument::OPTIONAL, "Feature(s) to run. Could be:" . "\n- a dir (<comment>src/to/Module/Features/</comment>), " . "\n- a feature (<comment>src/to/Module/Features/*.feature</comment>), "); }
/** * Registers a command. * * @param string $name Name of the command. * @param string $commandClass Class name of the command. */ public function addCommand($name, $commandClass) { // must extend AbstractCommand $abstractCommandClass = AbstractCommand::class; if (!Debugger::isExtending($commandClass, $abstractCommandClass)) { throw new InvalidCommandException('Command "' . $commandClass . '" must extend "' . $abstractCommandClass . '".'); } // name cannot be empty $name = trim($name); if (empty($name)) { throw new InvalidArgumentException('Command name cannot be empty for "' . $commandClass . '"!'); } // configure the command $console = $this; $consoleCommand = new ConsoleCommand($name); $consoleCommand->setDescription($commandClass::getDescription()); $consoleCommand->setHelp($commandClass::getHelp()); $consoleCommand->setCode(function (InputInterface $input, OutputInterface $output) use($console, $name) { $console->exec($name, $input, $output); }); // read some meta info about the command $commandReflection = new \ReflectionClass($commandClass); $arguments = array(); $argumentsDescriptions = $commandClass::getArguments(); try { $methodReflection = $commandReflection->getMethod('execute'); if (!$methodReflection->isPublic() || $methodReflection->isStatic()) { throw new InvalidCommandException('The "execute()" method for ommand "' . $commandClass . '" must be public and non-static.'); } // get the execute() method's arguments so we can translate them to CLI arguments $parametersReflection = $methodReflection->getParameters(); foreach ($parametersReflection as $param) { $optional = $param->isDefaultValueAvailable(); $paramName = $param->getName(); $arguments[] = array('name' => $paramName, 'optional' => $optional, 'default' => $optional ? $param->getDefaultValue() : null, 'description' => isset($argumentsDescriptions[$paramName]) ? $argumentsDescriptions[$paramName] : ''); } } catch (\ReflectionException $e) { throw new InvalidCommandException('Command "' . $commandClass . '" must implement public function "execute()"!'); } foreach ($arguments as $argument) { $consoleCommand->addArgument($argument['name'], $argument['optional'] ? InputArgument::OPTIONAL : InputArgument::REQUIRED, $argument['description'], $argument['default']); } // also register command's options $options = $commandClass::getOptions(); foreach ($options as $option => $optionInfo) { $value = isset($optionInfo['required']) && $optionInfo['required'] ? InputOption::VALUE_REQUIRED : (!isset($optionInfo['default']) || empty($optionInfo['default']) || $optionInfo['default'] === null ? InputOption::VALUE_NONE : InputOption::VALUE_OPTIONAL); $consoleCommand->addOption($option, isset($optionInfo['shortcut']) ? $optionInfo['shortcut'] : null, $value, isset($optionInfo['description']) ? $optionInfo['description'] : '', $value === InputOption::VALUE_REQUIRED || $value === InputOption::VALUE_NONE ? null : (isset($optionInfo['default']) ? $optionInfo['default'] : null)); } // register the command $this->commands[$name] = array('name' => $name, 'class' => $commandClass, 'command' => $consoleCommand, 'arguments' => $arguments, 'options' => $options); $this->consoleApplication->add($consoleCommand); }
/** * Configures command to be executable by the controller. * * @param Command $command */ public function configure(Command $command) { $command->addArgument('specs', InputArgument::REQUIRED, 'spec directory to run')->addOption('--dry-run', null, InputOption::VALUE_NONE, 'Invokes formatters without executing the steps & hooks.')->addOption('--strict', null, InputOption::VALUE_NONE, 'Fail if there are any undefined or pending steps.'); }
protected function createCommand($taskName) { $taskInfo = new TaskInfo(self::ROBOCLASS, $taskName); $task = new Command($taskInfo->getName()); $task->setDescription($taskInfo->getDescription()); $args = $taskInfo->getArguments(); foreach ($args as $name => $val) { if ($val === TaskInfo::PARAM_IS_REQUIRED) { $task->addArgument($name, InputArgument::REQUIRED); } elseif (is_array($val)) { $task->addArgument($name, InputArgument::IS_ARRAY, '', $val); } else { $task->addArgument($name, InputArgument::OPTIONAL, '', $val); } } $opts = $taskInfo->getOptions(); foreach ($opts as $name => $val) { if (empty($val)) { $task->addOption($name, '', InputOption::VALUE_NONE, ''); } else { $task->addOption($name, '', InputOption::VALUE_OPTIONAL, '', $val); } } return $task; }
public function addArgument($name, $mode = null, $description = '', $default = null) { return parent::addArgument($name, $this->normalizeMode('argument', $mode), $description, $default); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; $say = function (InputInterface $in, OutputInterface $out) { $phrase = $in->getArgument('phrase'); $out->writeln($phrase); }; $sayCommand = new Command('say'); $sayCommand->addArgument('phrase', InputArgument::OPTIONAL, ' The phrase you want to say', ' I don\'t have anything to say'); $sayCommand->setCode($say); $application = new Application(); $application->add($sayCommand); $application->run();
/** * {@inheritdoc} */ public function configure(Command $command) { $command->addArgument('seeds', InputArgument::IS_ARRAY | InputArgument::OPTIONAL); }