private function setOptionDescription(InputDefinition $definition, $name, $description) { $argument = $definition->getOption($name); if ($argument instanceof InputOption) { $argument->setDescription($description); } }
/** * * {@inheritdoc} * */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); foreach ($definition->getArguments() as $argument) { $totalWidth = max($totalWidth, strlen($argument->getName())); } if ($definition->getArguments()) { $this->writeText('<comment>Arguments:</comment>', $options); $this->writeText("\n"); foreach ($definition->getArguments() as $argument) { $this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth))); $this->writeText("\n"); } } if ($definition->getArguments() && $definition->getOptions()) { $this->writeText("\n"); } if ($definition->getOptions()) { $laterOptions = array(); $this->writeText('<comment>Options:</comment>', $options); foreach ($definition->getOptions() as $option) { if (strlen($option->getShortcut()) > 1) { $laterOptions[] = $option; continue; } $this->writeText("\n"); $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth))); } foreach ($laterOptions as $option) { $this->writeText("\n"); $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth))); } } }
private function buildInputDefinition() { $inputDefinition = new InputDefinition(); $inputDefinition->addArgument(new InputArgument('uno', InputArgument::REQUIRED)); $inputDefinition->addOption(new InputOption('due', null, InputOption::VALUE_NONE)); return $inputDefinition; }
/** * @param InputDefinition $inputDefinition * @param InputInterface $input */ public function init(InputDefinition $inputDefinition, InputInterface $input) { $options = new ProcessOptionCollection(); foreach ($inputDefinition->getOptions() as $optionName => $inputOption) { $optionValue = $input->getOption($optionName); if ($inputOption->getDefault() != $optionValue) { switch (true) { case in_array($optionName, $this->skipOptions): $option = null; break; case $inputOption->isArray() && $optionName == 'out': $option = new ProcessOptionOut($optionName, $optionValue); break; case $inputOption->isArray(): $option = new ProcessOptionArray($optionName, $optionValue); break; case $inputOption->isValueRequired(): case $inputOption->isValueOptional(): $option = new ProcessOptionScalar($optionName, $optionValue); break; default: $option = new ProcessOption($optionName); } if ($option) { $options->set($option); } } } $this->optionCollection = $options; }
/** * Get an InputDefinition formed by the arguments provided * * Effectively provides a passthrough for any input arguments provided * * @param array $args Arguments * @return InputDefinition */ protected function getInputDefinition(array $args) { $definition = new InputDefinition(); foreach ($args as $field => $value) { $definition->addArgument(new InputArgument($field)); } return $definition; }
public function testConfigure() { $pidFile = "pid.pid"; $poolCommand = "pool:command"; $command = new PoolControlCommand($this->runnerFactory, $this->pidFactory, $pidFile, $poolCommand); $command->setDefinition($this->inputDefinition); $this->inputDefinition->shouldReceive("addArgument")->once(); $command->configure(); }
public function testSignature() { $this->inputDefinition->shouldReceive("addArgument")->times(3); $commandName = "thread:command"; $command = new ThreadCommand($commandName, $this->runnerFactory); $command->setDefinition($this->inputDefinition); $command->configure(); $this->assertEquals($commandName, $command->getName()); }
/** * @return array */ public function providerMake() { $inputDefinition = new InputDefinition(); $inputDefinition->addOption(new InputOption('option_optional_default', null, InputOption::VALUE_OPTIONAL, '', 'default')); $inputDefinition->addOption(new InputOption('option_array_default_array', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)); $inputDefinition->addOption(new InputOption('option_none', null, InputOption::VALUE_NONE)); $inputDefinition->addOption(new InputOption('out', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)); return ['option_optional_default_default' => [$inputDefinition, new ArrayInput(['--option_optional_default' => 'default'], $inputDefinition)], 'option_optional_default_value' => [$inputDefinition, new ArrayInput(['--option_optional_default' => 'value'], $inputDefinition), '--option_optional_default \'value\''], 'option_array_default_array_default' => [$inputDefinition, new ArrayInput(['--option_array_default_array' => []], $inputDefinition)], 'option_array_default_array_value' => [$inputDefinition, new ArrayInput(['--option_array_default_array' => ['value1', 'value2']], $inputDefinition), '--option_array_default_array \'value1\' --option_array_default_array \'value2\''], 'option_none_default' => [$inputDefinition, new ArrayInput([], $inputDefinition)], 'option_none_default_value' => [$inputDefinition, new ArrayInput(['--option_none' => 'any'], $inputDefinition), '--option_none'], 'out_folder_skip' => [$inputDefinition, new ArrayInput(['--out' => ['folder', 'std']], $inputDefinition), '', ['out']], 'out_folder' => [$inputDefinition, new ArrayInput(['--out' => ['folder', 'std']], $inputDefinition), '--out \'folder/59adaf3f0820898ecf0da97ceab30eab\' --out \'std\'']]; }
public function testConstruct() { $poolCommand = "pool:command"; $pidFile = "pool.pid"; $this->inputDefinition->shouldReceive("addOption")->once(); $command = new PoolCommand($poolCommand, "thread:command", $pidFile, $this->pidFactory, $this->runnerFactory, []); $command->setDefinition($this->inputDefinition); $command->configure(); $this->assertEquals($poolCommand, $command->getName()); }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $nameWidth = 0; foreach ($definition->getOptions() as $option) { $nameLength = strlen($option->getName()) + 2; if ($option->getShortcut()) { $nameLength += strlen($option->getShortcut()) + 3; } $nameWidth = max($nameWidth, $nameLength); } foreach ($definition->getArguments() as $argument) { $nameWidth = max($nameWidth, strlen($argument->getName())); } ++$nameWidth; if ($definition->getArguments()) { $this->writeText('<comment>Arguments:</comment>', $options); $this->writeText("\n"); foreach ($definition->getArguments() as $argument) { $this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth))); $this->writeText("\n"); } } if ($definition->getArguments() && $definition->getOptions()) { $this->writeText("\n"); } if ($definition->getOptions()) { $this->writeText('<comment>Options:</comment>', $options); $this->writeText("\n"); foreach ($definition->getOptions() as $option) { $this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth))); $this->writeText("\n"); } } }
function let(CommandCollection $collection, Command $command1, Command $command2, InputDefinition $inputDefinition, InputDefinition $inputDefinition2, InputOption $inputOption, InputOption $inputOption2) { $inputDefinition->getOptions()->willReturn(['option1' => $inputOption, 'option2' => $inputOption2]); $command1->getName()->willReturn('test:command'); $command1->getDefinition()->willReturn($inputDefinition); $inputDefinition2->getOptions()->willReturn([]); $command2->getName()->willReturn('other-command'); $command2->getDefinition()->willReturn($inputDefinition2); $collection->getItems()->willReturn(['test:command' => $command1, 'other-command' => $command2]); $this->beConstructedWith($collection); }
private function getInputDefinitionData(InputDefinition $definition) { $inputArguments = array(); foreach ($definition->getArguments() as $name => $argument) { $inputArguments[$name] = $this->getInputArgumentData($argument); } $inputOptions = array(); foreach ($definition->getOptions() as $name => $option) { $inputOptions[$name] = $this->getInputOptionData($option); } return array('arguments' => $inputArguments, 'options' => $inputOptions); }
public function testConfigureSystemCommand() { $name = 'test_base_command'; $description = 'test for base command creation'; $keywords = 'base commands creation test'; $arguments = array('username' => array('description' => 'linux username')); $options = 'options'; $expectedArguments = new InputDefinition(); $expectedArguments->addArgument(new InputArgument('username', InputArgument::REQUIRED, $arguments['username']['description'])); $systemCommand = new SystemCommand($name, $description, $keywords, $arguments, $options); $this->assertEquals($expectedArguments, $systemCommand->getDefinition()); }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $inputArguments = array(); foreach ($definition->getArguments() as $name => $argument) { $inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true)); } $inputOptions = array(); foreach ($definition->getOptions() as $name => $option) { $inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true)); } return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options); }
protected function configure() { parent::configure(); $definition = new InputDefinition(); $definition->setDefinition(array(new InputArgument('username', InputArgument::REQUIRED, 'The username'), new InputArgument('role', InputArgument::OPTIONAL, 'The role'), new InputOption('user-system', null, InputOption::VALUE_REQUIRED, 'The user-system to use'), new InputOption('super', null, InputOption::VALUE_NONE, 'Instead specifying role, use this to quickly add the super administrator role'))); $this->setDefinition($definition); $this->setHelp(<<<EOT The <info>fos:user:demote</info> command demotes a user by removing a role <info>php app/console fos:user:demote --user-system=acme_user matthieu ROLE_CUSTOM</info> <info>php app/console fos:user:demote --user-system=acme_user --super matthieu</info> EOT ); }
/** * @param InputDefinition $definition * * @return \DOMDocument */ public function getInputDefinitionDocument(InputDefinition $definition) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($definitionXML = $dom->createElement('definition')); $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments')); foreach ($definition->getArguments() as $argument) { $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument)); } $definitionXML->appendChild($optionsXML = $dom->createElement('options')); foreach ($definition->getOptions() as $option) { $this->appendDocument($optionsXML, $this->getInputOptionDocument($option)); } return $dom; }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($definitionXML = $dom->createElement('definition')); $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments')); foreach ($definition->getArguments() as $argument) { $this->appendDocument($argumentsXML, $this->describeInputArgument($argument, array('as_dom' => true))); } $definitionXML->appendChild($optionsXML = $dom->createElement('options')); foreach ($definition->getOptions() as $option) { $this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true))); } return $this->output($dom, $options); }
public function setUp() { parent::setUp(); $this->template = $this->prophesize(TemplateInterface::class); $inputDef = new InputDefinition(); $inputDef->addOption(new InputOption('test-option', null, InputOption::VALUE_OPTIONAL)); $this->input = new ArrayInput(['--test-option' => null], $inputDef); $this->output = new BufferedOutput(); $this->application = $this->getApplication(); $styleHelper = $this->application->getHelperSet()->get('gush_style'); $styleHelper->setInput($this->input); $styleHelper->setOutput($this->output); $this->helper = new TemplateHelper($styleHelper, $this->application); $this->helper->setInput($this->input); }
/** * Start workers, put master port, server name to run on, and options stuff. */ public function startWorkers() { // Get verbosity. $verbosity = new VerbosityString($this->output); // Get current deploy.php file. $deployPhpFile = $this->input->getOption('file'); // User input. $input = ''; // Get user arguments. foreach ($this->userDefinition->getArguments() as $argument) { $value = $this->input->getArgument($argument->getName()); if ($value) { $input .= " {$value}"; } } // Get user options. foreach ($this->userDefinition->getOptions() as $option) { $value = $this->input->getOption($option->getName()); if ($value) { $input .= " --{$option->getName()} {$value}"; } } foreach ($this->servers as $serverName => $server) { $process = new Process("php " . DEPLOYER_BIN . (null === $deployPhpFile ? "" : " --file={$deployPhpFile}") . " worker " . " --master 127.0.0.1:{$this->port}" . " --server {$serverName}" . " {$input} " . " {$verbosity}" . " &"); $process->disableOutput(); $process->start(); } }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $blocks = array(); if (count($definition->getArguments()) > 0) { $blocks[] = '### Arguments:'; foreach ($definition->getArguments() as $argument) { $blocks[] = $this->describeInputArgument($argument); } } if (count($definition->getOptions()) > 0) { $blocks[] = '### Options:'; foreach ($definition->getOptions() as $option) { $blocks[] = $this->describeInputOption($option); } } return implode("\n\n", $blocks); }
/** * @return array Values for given InputDefinition, optionally filtered */ public function resolveInputDefinition(InputDefinition $inputDefinition, array $filter = []) { $values = []; $arguments = array_filter($inputDefinition->getArguments(), function (InputArgument $argument) use($filter) { return !count($filter) || in_array($argument->getName(), $filter); }); $options = array_filter($inputDefinition->getOptions(), function (InputOption $option) use($filter) { return !count($filter) || in_array($option->getName(), $filter); }); foreach ($arguments as $argument) { $values[$argument->getName()] = $this->input->getArgument($argument->getName()); } foreach ($options as $option) { $values[$option->getName()] = $this->getOptionValue($option); } return $values; }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $nameWidth = 0; foreach ($definition->getOptions() as $option) { $nameLength = strlen($option->getName()) + 2; if ($option->getShortcut()) { $nameLength += strlen($option->getShortcut()) + 3; } $nameWidth = max($nameWidth, $nameLength); } foreach ($definition->getArguments() as $argument) { $nameWidth = max($nameWidth, strlen($argument->getName())); } ++$nameWidth; $messages = array(); if ($definition->getArguments()) { $messages[] = '<comment>Arguments:</comment>'; foreach ($definition->getArguments() as $argument) { $messages[] = $this->describeInputArgument($argument, array('name_width' => $nameWidth)); } $messages[] = ''; } if ($definition->getOptions()) { $messages[] = '<comment>Options:</comment>'; foreach ($definition->getOptions() as $option) { $messages[] = $this->describeInputOption($option, array('name_width' => $nameWidth)); } $messages[] = ''; } $output = implode("\n", $messages); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; }
/** * @inheritdoc */ public static function run($request, $response, $args) { global $argv; $container = static::getApp()->getContainer(); $pathResolver = $container['pathResolver']; $filesystem = new Filesystem(); $creator = new MigrationCreator($filesystem); $definition = new InputDefinition(); $definition->addArgument(new InputArgument('name', InputArgument::REQUIRED)); $definition->addOption(new InputOption('table', 't', InputOption::VALUE_OPTIONAL)); $input = new ArgvInput(array_slice($argv, 1), $definition); $output = new ConsoleOutput(); $path = $pathResolver->getAlias('@db/migrations'); $name = $input->getArgument('name'); $table = $input->getOption('table'); $file = pathinfo($creator->create($name, $path, $table), PATHINFO_FILENAME); \dump($file); }
/** * @see Symfony\Component\Console\Command.Command::configure() */ protected function configure() { $definition = new InputDefinition(); $definition->addArgument(new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace to process')); $definition->addArgument(new InputArgument('path', InputArgument::REQUIRED, 'The path the namespace can be found in')); $definition->addOption(new InputOption('output', 'o', InputOption::VALUE_REQUIRED, 'The path to output the ReST files', 'build')); $definition->addOption(new InputOption('title', 't', InputOption::VALUE_REQUIRED, 'An alternate title for the top level namespace', null)); $definition->addOption(new InputOption('exclude', 'x', InputOption::VALUE_REQUIRED, 'Semicolon separated namespaces to ignore', null)); $definition->addOption(new InputOption('filters', 'f', InputOption::VALUE_REQUIRED, 'Semicolon separated filename filters to apply', null)); $this->setName('process')->setDescription('Processes a directory of PHPDoc documented code into ReST')->setHelp('The process command works recursively on a directory of PHP code.')->setDefinition($definition); }
/** * @param string|\Symfony\Component\Form\FormTypeInterface $formType * @param array &$resources * * @return InputDefinition */ public function createForFormType($formType, array &$resources = []) { $resources[] = new FileResource(__FILE__); $form = $this->formFactory->create($formType); $actualFormType = $form->getConfig()->getType()->getInnerType(); $reflection = new \ReflectionObject($actualFormType); $resources[] = new FileResource($reflection->getFileName()); $inputDefinition = new InputDefinition(); foreach ($form->all() as $name => $field) { if (!$this->isFormFieldSupported($field)) { continue; } $type = InputOption::VALUE_REQUIRED; $default = $field->getConfig()->getOption('data', null); $description = FormUtil::label($field); $inputDefinition->addOption(new InputOption($name, null, $type, $description, $default)); } return $inputDefinition; }
/** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { if ($showArguments = count($definition->getArguments()) > 0) { $this->write('### Arguments:'); foreach ($definition->getArguments() as $argument) { $this->write("\n\n"); $this->write($this->describeInputArgument($argument)); } } if (count($definition->getOptions()) > 0) { if ($showArguments) { $this->write("\n\n"); } $this->write('### Options:'); foreach ($definition->getOptions() as $option) { $this->write("\n\n"); $this->write($this->describeInputOption($option)); } } }
/** * @test */ public function configCommandAlias() { $config = new Config(); $input = new ArgvInput(); $actual = $config->checkConfigCommandAlias($input); $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface', $actual); $saved = $_SERVER['argv']; $config->setConfig(array('commands' => array('aliases' => array(array('list-help' => 'list --help'))))); $definition = new InputDefinition(); $definition->addArgument(new InputArgument('command')); $argv = array('/path/to/command', 'list-help'); $_SERVER['argv'] = $argv; $input = new ArgvInput($argv, $definition); $this->assertSame('list-help', (string) $input); $actual = $config->checkConfigCommandAlias($input); $this->assertSame('list-help', $actual->getFirstArgument()); $this->assertSame('list-help --help', (string) $actual); $_SERVER['argv'] = $saved; $command = new Command('list'); $config->registerConfigCommandAlias($command); $this->assertSame(array('list-help'), $command->getAliases()); }
/** * Define input definition for peridot */ public function __construct() { parent::__construct([]); $this->addArgument(new InputArgument('path', InputArgument::OPTIONAL, 'The path to a directory or file containing specs')); $this->addOption(new InputOption('grep', 'g', InputOption::VALUE_REQUIRED, 'Run tests matching <pattern> <comment>(default: *.spec.php)</comment>')); $this->addOption(new InputOption('no-colors', 'C', InputOption::VALUE_NONE, 'Disable output colors')); $this->addOption(new InputOption('reporter', 'r', InputOption::VALUE_REQUIRED, 'Select which reporter to use <comment>(default: spec)</comment>')); $this->addOption(new InputOption('bail', 'b', InputOption::VALUE_NONE, 'Stop on failure')); $this->addOption(new InputOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'A php file containing peridot configuration')); $this->addOption(new InputOption('reporters', null, InputOption::VALUE_NONE, 'List all available reporters')); $this->addOption(new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display the Peridot version number')); $this->addOption(new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.')); }
/** * @param InputInterface $input * @param $appDefinition * @return ArrayInput */ public function filterByOriginalDefinition(InputInterface $input, $appDefinition) { $newDefinition = new InputDefinition(); $newInput = new ArrayInput(array(), $newDefinition); foreach ($input->getArguments() as $name => $value) { if (!$appDefinition->hasArgument($name)) { $newDefinition->addArgument($this->getDefinition()->getArgument($name)); if (!empty($value)) { $newInput->setArgument($name, $value); } } } foreach ($input->getOptions() as $name => $value) { if (!$appDefinition->hasOption($name)) { $newDefinition->addOption($this->getDefinition()->getOption($name)); if (!empty($value)) { $newInput->setOption($name, $value); } } } return $newInput; }
/** * Returns true if an InputOption object exists by name. * * @param string $name The InputOption name * * @return Boolean true if the InputOption object exists, false otherwise * * @api */ public function hasOption($name) { if (parent::hasOption($name)) { return true; } if ('no-' === substr($name, 0, 3) && parent::hasOption('[no-]' . substr($name, 3))) { return true; } if (parent::hasOption('[no-]' . $name)) { return true; } return false; }