private function validateCommandName(CommandConfig $config) { $name = $config->getName(); if (!$name) { throw CannotAddCommandException::nameEmpty(); } if ($this->commands->contains($name)) { throw CannotAddCommandException::nameExists($name); } }
public function testClear() { $this->collection->add(new Command(new OptionCommandConfig('ls', 'l'))); $this->collection->add(new Command(CommandConfig::create('cd')->addAlias('cd-alias'))); $this->assertTrue($this->collection->contains('ls')); $this->assertTrue($this->collection->contains('l')); $this->assertTrue($this->collection->contains('cd')); $this->assertTrue($this->collection->contains('cd-alias')); $this->collection->clear(); $this->assertFalse($this->collection->contains('ls')); $this->assertFalse($this->collection->contains('l')); $this->assertFalse($this->collection->contains('cd')); $this->assertFalse($this->collection->contains('cd-alias')); }
/** * @param RawArgs $args * @param CommandCollection $namedCommands * @param string[] $argumentsToTest * @param string[] $optionsToTest * * @return ResolveResult */ private function processArguments(RawArgs $args, CommandCollection $namedCommands, array $argumentsToTest, array $optionsToTest) { $currentCommand = null; // Parse the arguments for command names until we fail to find a // matching command foreach ($argumentsToTest as $name) { if (!$namedCommands->contains($name)) { break; } $nextCommand = $namedCommands->get($name); if ($nextCommand->getConfig() instanceof OptionCommandConfig) { break; } $currentCommand = $nextCommand; $namedCommands = $currentCommand->getNamedSubCommands(); } if (!$currentCommand) { return null; } return $this->processOptions($args, $currentCommand, $optionsToTest); }
private function validateSubCommandName(SubCommandConfig $config) { $name = $config->getName(); if (!$name) { throw CannotAddCommandException::nameEmpty(); } if ($this->subCommands->contains($name)) { throw CannotAddCommandException::nameExists($name); } if ($config instanceof OptionCommandConfig) { if ($this->argsFormat->hasOption($name)) { throw CannotAddCommandException::optionExists($name); } if ($shortName = $config->getShortName()) { if ($this->subCommands->contains($shortName)) { throw CannotAddCommandException::nameExists($name); } if ($this->argsFormat->hasOption($shortName)) { throw CannotAddCommandException::optionExists($shortName); } } } }