/** * @param IInput $input * @param IConsole $console * * @return ICommand * @throws AmbiguousCommandException * @throws CommandNotFoundException */ protected function findCommand(IInput $input, IConsole $console) { if ($input->hasArgument('command')) { $matcher = new ArgumentsMatcher(new ArgumentsParser()); return $matcher->findCommand($console->getCommands(), $input->getArgument('command')); } return $input->getCommand(); }
function it_renders_without_Commands(IConsole $console) { $console->getCommands()->willReturn([]); $input = new Input(); $output = new Output(); $output->setEnableBuffering(true); $this->beConstructedWith($input, $output); $this->render($console); }
function it_runs(IInput $input, IConsole $console) { $console->getCommands()->willReturn([new Command('test')]); $input->hasArgument('command')->willReturn(true); $input->getArgument('command')->willReturn('test'); $output = new Output(); $output->setEnableBuffering(true); $this->run($input, $output, $console); }
/** * Render options. */ public function render() { $table = new TableWidget($this->input, $this->output); $table->setTitle("<header>Global options:</header>"); foreach ($this->console->getCommands() as $command) { if ($command->isGlobal()) { foreach ($command->getOptions() as $option) { $name = $option->getName(); $alias = ' '; if ($option->getAlias()) { $alias = $option->getAlias(); if ($option->isIncremental()) { $alias = s('-:a|:a:a|:a:a:a', [':a' => substr($alias, 1)]); } $alias .= ','; } $table->addRow("<keyword>{$alias} {$name}</keyword>", $option->getDescription()); } } } $this->output->writeLine(); $table->render(); }
/** * @param IConsole $console */ public function render(IConsole $console) { $facts = $this->gatherFacts($console->getCommands()); if (count($facts) > 0) { $table = new TableWidget($this->input, $this->output); $table->setTitle("<header>Available commands:</header>"); $headers = []; foreach ($facts as $name => $description) { if (stripos($name, ':') !== false) { $header = array_first(explode(':', $name)); if (!array_contains($headers, $header)) { $headers[] = $header; $table->addSection("<header>{$header}</header>"); } } $table->addRow("<keyword>{$name}</keyword>", $description); } $this->output->writeLine(); $table->render(); } else { $this->output->writeLineIndented('There are no commands yet'); } }