/** * Test CommandInfo command annotation parsing. */ function testParsing() { $commandInfo = new CommandInfo('\\Consolidation\\TestUtils\\ExampleCommandFile', 'testArithmatic'); $this->assertEquals('test:arithmatic', $commandInfo->getName()); $this->assertEquals('This is the test:arithmatic command', $commandInfo->getDescription()); $this->assertEquals("This command will add one and two. If the --negate flag\nis provided, then the result is negated.", $commandInfo->getHelp()); $this->assertEquals('arithmatic', implode(',', $commandInfo->getAliases())); $this->assertEquals('2 2 --negate=>Add two plus two and then negate.', $this->flattenArray($commandInfo->getExampleUsages())); $this->assertEquals('The first number to add.', $commandInfo->arguments()->getDescription('one')); $this->assertEquals('The other number to add.', $commandInfo->arguments()->getDescription('two')); $this->assertEquals('Whether or not the result should be negated.', $commandInfo->options()->getDescription('negate')); }
/** * Store the data from a @default annotation in our argument or option store, * as appropriate. */ protected function processDefaultTag($tag) { if (!$this->pregMatchNameAndDescription((string) $tag->getDescription(), $match)) { return; } $variableName = $match['name']; $defaultValue = $this->interpretDefaultValue($match['description']); if ($this->commandInfo->arguments()->exists($variableName)) { $this->commandInfo->arguments()->setDefaultValue($variableName, $defaultValue); return; } $variableName = $this->commandInfo->findMatchingOption($variableName); if ($this->commandInfo->options()->exists($variableName)) { $this->commandInfo->options()->setDefaultValue($variableName, $defaultValue); } }
/** * Register a command hook given the CommandInfo for a method. * * The hook format is: * * @hook type name type * * For example, the pre-validate hook for the core:init command is: * * @hook pre-validate core:init * * If no command name is provided, then this hook will affect every * command that is defined in the same file. * * If no hook is provided, then we will presume that ALTER_RESULT * is intended. * * @param CommandInfo $commandInfo Information about the command hook method. * @param object $commandFileInstance An instance of the CommandFile class. */ public function registerCommandHook(CommandInfo $commandInfo, $commandFileInstance) { // Ignore if the command info has no @hook if (!$commandInfo->hasAnnotation('hook')) { return; } $hookData = $commandInfo->getAnnotation('hook'); $hook = $this->getNthWord($hookData, 0, HookManager::ALTER_RESULT); $commandName = $this->getNthWord($hookData, 1); // Register the hook $callback = [$commandFileInstance, $commandInfo->getMethodName()]; $this->commandProcessor()->hookManager()->add($callback, $hook, $commandName); // If the hook has options, then also register the commandInfo // with the hook manager, so that we can add options and such to // the commands they hook. if (!$commandInfo->options()->isEmpty()) { $this->commandProcessor()->hookManager()->recordHookOptions($commandInfo, $commandName); } }