getName() public method

Returns the command name.
public getName ( ) : string
return string The command name
Example #1
2
 /**
  * @param $condition
  * @param $message
  */
 private function assert($condition, $message)
 {
     if ($condition) {
         return;
     }
     throw new RuntimeException(sprintf('Command %s is not available because %s.', $this->command->getName(), $message));
 }
Example #2
2
 /**
  * @param Command $command
  * @return array
  */
 public function getDependencies(Command $command)
 {
     if (!array_key_exists($command->getName(), $this->commands)) {
         return [];
     }
     return array_keys($this->commands[$command->getName()]);
 }
 /**
  * Test executing "mark_migration"
  *
  * @return void
  */
 public function testExecute()
 {
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(['command' => $this->command->getName(), 'version' => '20150416223600', '--connection' => 'test']);
     $this->assertContains('Migration successfully marked migrated !', $commandTester->getDisplay());
     $result = $this->Connection->newQuery()->select(['*'])->from('phinxlog')->execute()->fetch('assoc');
     $this->assertEquals('20150416223600', $result['version']);
 }
 /**
  * {@inheritdoc}
  */
 protected function getCommandName(InputInterface $input)
 {
     $stream = $this->getStdinStream();
     $hasStdin = $stream->getSize() > 0;
     $this->pluginCommand->setStream($stream);
     return $hasStdin ? $this->pluginCommand->getName() : $this->generateCommand->getName();
 }
 /**
  * @inheritdoc
  */
 protected function describeCommand(Command $command, array $options = [])
 {
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $this->write($command->getName() . "\n" . str_repeat('-', strlen($command->getName())) . "\n");
     if ($description = $command->getDescription()) {
         $this->write("{$description}\n\n");
     }
     $aliases = $command instanceof CommandBase ? $command->getVisibleAliases() : $command->getAliases();
     if ($aliases) {
         $this->write('Aliases: ' . '`' . implode('`, `', $aliases) . '`' . "\n\n");
     }
     $executableName = 'platform';
     $this->write("## Usage:\n\n```\n{$executableName} " . $command->getSynopsis() . "\n```\n\n");
     if ($help = $command->getProcessedHelp()) {
         $this->write($help);
         $this->write("\n\n");
     }
     if ($command->getNativeDefinition()) {
         $this->describeInputDefinition($command->getNativeDefinition());
         $this->write("\n\n");
     }
     if ($command instanceof CommandBase && ($examples = $command->getExamples())) {
         $this->write('## Examples');
         $this->write("\n");
         $name = $command->getName();
         foreach ($examples as $arguments => $description) {
             $this->write("\n* {$description}:  \n  ```\n  platform {$name} {$arguments}\n  ```\n");
         }
         $this->write("\n");
     }
 }
Example #6
0
 private function execute(array $fileStructure, array $options = []) : CommandTester
 {
     $fs = vfsStream::create($fileStructure, vfsStream::setup(getcwd()));
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(array_merge(['command' => $this->command->getName(), 'path' => $fs->url()], $options));
     return $commandTester;
 }
 public function testDumpCommandExecute()
 {
     /** @var OrganizeCommand $command */
     $noTagDir = __DIR__ . '/NO_TAG';
     $this->commandTester->execute(['command' => $this->command->getName(), 'output-dir' => __DIR__, '--file-dir' => realpath(__DIR__ . '/../'), '--dump-command' => ' ', '--move-untagged-to' => $noTagDir]);
     $output = $this->commandTester->getDisplay();
     $outputArray = array_map('trim', explode(PHP_EOL, $output));
     $this->assertEquals('mv \'' . realpath(__DIR__ . '/../') . '/toddle.mp3\' \'' . __DIR__ . '/2003/Celtic/toddle.mp3\'', $outputArray[0]);
     $this->assertEquals('mv \'' . realpath(__DIR__ . '/../') . '/wrong_file.mp3\' \'' . __DIR__ . '/NO_TAG/wrong_file.mp3\'', $outputArray[1]);
 }
Example #8
0
 /**
  * Unique file name pid file name.
  *
  * @param Command $command
  * @param null|string $tmpDirectory
  */
 public function __construct(Command $command, $tmpDirectory = null)
 {
     $tmpDirectory = $tmpDirectory ? $tmpDirectory : sys_get_temp_dir();
     if (!is_dir($tmpDirectory) or !is_writable($tmpDirectory)) {
         throw new \RuntimeException(sprintf('The directory "%s" is not writable.', $tmpDirectory), 0, null, $tmpDirectory);
     }
     $partName = preg_replace('/[^a-z0-9\\._-]+/i', '-', $command->getName());
     $partName = substr($partName, 0, 40);
     $this->pidFile = sprintf('%s/atl.%s.%s.pid', $tmpDirectory, $partName, hash('sha256', $command->getName()));
 }
 /** @test */
 public function it_opens_a_dialog_to_select_the_entity_and_count_if_no_entity_given()
 {
     /** @var SymfonyQuestionHelper $question */
     $question = $this->command->getHelper('question');
     $question->setInputStream($this->getInputStream("1\n5\n"));
     $this->commandTester->execute(['command' => $this->command->getName()]);
     $count = $this->getDatabaseCount(App::class, []);
     $this->assertEquals(5, $count);
     $this->assertContains(sprintf('%s seeded.', App::class), $this->commandTester->getDisplay());
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  *
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ssh = $this->getApplication()->find($this->vagrant_ssh);
     $arguments = $this->basicGetArgumentsWithoutSelf($input);
     $options = $input->getOptions();
     $parameters = array('command' => $this->vagrant_ssh, '--ssh_command' => $this->command->getName(), '--ssh_command_arguments' => $this->basicProceedArray($arguments), '--ssh_command_options' => $this->basicProceedArray($options));
     $output->writeln($this->helper->formatSection('Info', json_encode($parameters)));
     $greetInput = new ArrayInput($parameters);
     $returnCode = $ssh->run($greetInput, $output);
     $output->writeln($this->helper->formatSection('Finishing', $returnCode));
 }
 /**
  * Check if table without shop id was created as expected.
  */
 public function testExecuteWithoutShopId()
 {
     $defaultStorage = 'ongr_sync_storage_0';
     $commandTester = new CommandTester($this->executeCommand);
     $commandTester->execute(['command' => $this->executeCommand->getName(), 'storage' => SyncStorage::STORAGE_MYSQL]);
     $this->assertEquals('Storage successfully created for ' . SyncStorage::STORAGE_MYSQL . '.' . PHP_EOL, $commandTester->getDisplay());
     $actual = $this->getConnection()->getSchemaManager()->listTableDetails($defaultStorage);
     $this->getConnection()->getSchemaManager()->dropTable($defaultStorage);
     $this->importData('SyncStorage/storageWithoutShop.sql');
     $expected = $this->getConnection()->getSchemaManager()->listTableDetails($defaultStorage);
     $this->compareTable($expected, $actual);
 }
 /**
  * {@inheritdoc}
  */
 protected function describeCommand(Command $command, array $options = array())
 {
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $markdown = $command->getName() . "\n" . str_repeat('-', strlen($command->getName())) . "\n\n" . '* Description: ' . ($command->getDescription() ?: '<none>') . "\n" . '* Usage: `' . $command->getSynopsis() . '`' . "\n" . '* Aliases: ' . (count($command->getAliases()) ? '`' . implode('`, `', $command->getAliases()) . '`' : '<none>');
     if ($help = $command->getProcessedHelp()) {
         $markdown .= "\n\n" . $help;
     }
     if ($definitionMarkdown = $this->describeInputDefinition($command->getNativeDefinition())) {
         $markdown .= "\n\n" . $definitionMarkdown;
     }
     return $markdown;
 }
Example #13
0
 protected function cmdNameToResourceName(Command $command, Page $parentPage)
 {
     $conf = $parentPage->getConfig();
     $strategy = self::CHILDNAME_STRATEGY_PREFIX;
     if (array_key_exists(self::CONF_CHILDNAME_STRATEGY, $conf)) {
         $strategy = $conf[self::CONF_CHILDNAME_STRATEGY];
     }
     if ($strategy === self::CHILDNAME_STRATEGY_PREFIX) {
         return sprintf('%s__%s.html', $parentPage->getName(), str_replace(':', '__', $command->getName()));
     } else {
         return sprintf('%s.html', str_replace(':', '__', $command->getName()));
     }
 }
 public function __construct(Command $singleCommand)
 {
     global $argv;
     $this->singleCommand = $singleCommand;
     // Use the command's name as the whole app's name
     $this->setName($singleCommand->getName());
     // Then set the command's name to be the name of the script file
     //  executed (as executed, regardless of symlinks, etc) - i.e.
     //  whatever's set as $argv[0] - because this name ends up displayed in
     //  the "Usage" line of the `--help` output. Though we use the executed
     //  script's base name (i.e. none of the directories leading to it)
     //  because including any parts of the directory path results in a
     //  `--help` output that's very different to all native/standard
     //  commands.
     // This will result in the "Usage" section displaying as:
     //     my-command.php [options] [--] <arguments>
     //  instead of showing the name of the command in place of
     //  'my-command.php', which is especially useful for single-command
     //  apps, as the command name is never even referenced anywhere else!
     $commandName = isset($argv[0]) ? basename($argv[0]) : 'command.php';
     $singleCommand->setName($commandName);
     parent::__construct();
     $this->add($singleCommand);
     $this->setDefaultCommand($singleCommand->getName());
     // If the command class has an 'APP_VERSION' constant defined, we use
     //  that as the entire app's version, as this seems like a much more
     //  sensible place to indicate the version than in the Application
     //  constructor which is tucked away in a non-obvious place!
     $commandClass = get_class($singleCommand);
     if (defined($commandClass . '::APP_VERSION')) {
         $this->setVersion(constant($commandClass . '::APP_VERSION'));
     }
 }
Example #15
0
 /**
  * @inheritdoc
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if ($command->getName() != 'version') {
         $output->writeln($this->getLongVersion());
     }
     return parent::doRunCommand($command, $input, $output);
 }
 /**
  * @inheritdoc
  */
 protected function describeCommand(Command $command, array $options = array())
 {
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $this->writeText("<comment>Command:</comment> " . $command->getName(), $options);
     if ($aliases = $command->getAliases()) {
         $this->writeText("\n");
         $this->writeText('<comment>Aliases:</comment> ' . implode(', ', $aliases), $options);
     }
     if ($description = $command->getDescription()) {
         $this->writeText("\n");
         $this->writeText("<comment>Description:</comment> {$description}", $options);
     }
     $this->writeText("\n\n");
     $this->writeText('<comment>Usage:</comment>', $options);
     $this->writeText("\n");
     $this->writeText(' ' . $command->getSynopsis(), $options);
     $this->writeText("\n");
     if ($definition = $command->getNativeDefinition()) {
         $this->writeText("\n");
         $this->describeInputDefinition($definition, $options);
     }
     if ($help = $command->getProcessedHelp()) {
         $this->writeText("\n");
         $this->writeText('<comment>Help:</comment>', $options);
         $this->writeText("\n");
         $this->writeText(' ' . str_replace("\n", "\n ", $help), $options);
         $this->writeText("\n");
     }
 }
Example #17
0
 private function updateCommandDefinition(Command $command, OutputInterface $output)
 {
     $eventDispatcher = $this->getApplication()->getDispatcher();
     $input = new ArrayInput(['command' => $command->getName()]);
     $event = new ConsoleCommandEvent($command, $input, $output);
     $eventDispatcher->dispatch(GushEvents::DECORATE_DEFINITION, $event);
     $command->getSynopsis(true);
     $command->getSynopsis(false);
     $command->mergeApplicationDefinition();
     try {
         $input->bind($command->getDefinition());
     } catch (\Exception $e) {
         $output->writeln('<error>Something went wrong: </error>' . $e->getMessage());
         return;
     }
     $eventDispatcher->dispatch(GushEvents::INITIALIZE, $event);
     // The options were set on the input but now we need to set them on the Command definition
     if ($options = $input->getOptions()) {
         foreach ($options as $name => $value) {
             $option = $command->getDefinition()->getOption($name);
             if ($option->acceptValue()) {
                 $option->setDefault($value);
             }
         }
     }
 }
Example #18
0
 public function add(Command $command, $namespace = '')
 {
     if (strlen($namespace)) {
         $command->setName($namespace . ':' . $command->getName());
     }
     $this->app->add($command);
 }
 /**
  * {@inheritdoc}
  */
 protected function describeCommand(Command $command, array $options = array())
 {
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $this->write($command->getName() . "\n" . str_repeat('-', strlen($command->getName())) . "\n\n" . '* Description: ' . ($command->getDescription() ?: '<none>') . "\n" . '* Usage:' . "\n\n" . array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
         return $carry .= '  * `' . $usage . '`' . "\n";
     }));
     if ($help = $command->getProcessedHelp()) {
         $this->write("\n");
         $this->write($help);
     }
     if ($command->getNativeDefinition()) {
         $this->write("\n\n");
         $this->describeInputDefinition($command->getNativeDefinition());
     }
 }
 function it_should_be_countable(Command $command1, Command $command2)
 {
     $command1->getName()->willReturn('abc');
     $command2->getName()->willReturn('cba');
     $this->add($command1);
     $this->add($command2);
     $this->count()->shouldBe(2);
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function renderException(\Exception $e, OutputInterface $output)
 {
     $output->writeln('', OutputInterface::VERBOSITY_QUIET);
     do {
         $exceptionName = get_class($e);
         if (($pos = strrpos($exceptionName, '\\')) !== false) {
             $exceptionName = substr($exceptionName, $pos + 1);
         }
         $title = sprintf('  [%s]  ', $exceptionName);
         $len = strlen($title);
         $width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
         // HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
         if (defined('HHVM_VERSION') && $width > 1 << 31) {
             $width = 1 << 31;
         }
         $formatter = $output->getFormatter();
         $lines = array();
         foreach (preg_split('/\\r?\\n/', $e->getMessage()) as $line) {
             foreach (str_split($line, $width - 4) as $chunk) {
                 // pre-format lines to get the right string length
                 $lineLength = strlen(preg_replace('/\\[[^m]*m/', '', $formatter->format($chunk))) + 4;
                 $lines[] = array($chunk, $lineLength);
                 $len = max($lineLength, $len);
             }
         }
         $messages = array();
         $messages[] = $emptyLine = $formatter->format(sprintf('<error>%s</error>', str_repeat(' ', $len)));
         $messages[] = $formatter->format(sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - strlen($title)))));
         foreach ($lines as $line) {
             $messages[] = $formatter->format(sprintf('<error>  %s  %s</error>', $line[0], str_repeat(' ', $len - $line[1])));
         }
         $messages[] = $emptyLine;
         $messages[] = '';
         $output->writeln($messages, OutputInterface::OUTPUT_RAW | OutputInterface::VERBOSITY_QUIET);
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
             // exception related properties
             $trace = $e->getTrace();
             array_unshift($trace, array('function' => '', 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', 'args' => array()));
             for ($i = 0, $count = count($trace); $i < $count; ++$i) {
                 $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
                 $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
                 $function = $trace[$i]['function'];
                 $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
                 $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
                 $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line), OutputInterface::VERBOSITY_QUIET);
             }
             $output->writeln('', OutputInterface::VERBOSITY_QUIET);
         }
     } while ($e = $e->getPrevious());
     if (null !== $this->currentCommand && $this->currentCommand->getName() !== 'welcome') {
         $output->writeln(sprintf('Usage: <info>%s</info>', $this->currentCommand->getSynopsis()), OutputInterface::VERBOSITY_QUIET);
         $output->writeln('', OutputInterface::VERBOSITY_QUIET);
         $output->writeln(sprintf('For more information, type: <info>%s help %s</info>', $this->cliConfig->get('application.executable'), $this->currentCommand->getName()), OutputInterface::VERBOSITY_QUIET);
         $output->writeln('', OutputInterface::VERBOSITY_QUIET);
     }
 }
 /**
  * Executes a symfony command and returns the testing instance.
  *
  * @param Command $command
  * @param array   $input
  *
  * @return CommandTester
  */
 public function executeCommand(Command $command, array $input = []) : CommandTester
 {
     $name = $command->getName();
     $application = new Application();
     $application->add($command);
     $tester = new CommandTester($application->find($name));
     $tester->execute(array_merge(['command' => $name], $input));
     return $tester;
 }
 /**
  * Constructor to build a "single command" application, given a command.
  *
  * The application will adopt the same name as the command.
  *
  * @param Command $command The single (accessible) command for this application
  * @param string $version The version of the application
  */
 public function __construct(Command $command, $version = 'UNKNOWN')
 {
     parent::__construct($command->getName(), $version);
     // Add the given command as single (accessible) command.
     $this->add($command);
     $this->commandName = $command->getName();
     // Override the Application's definition so that it does not
     // require a command name as first argument.
     $this->getDefinition()->setArguments();
 }
Example #24
0
 /**
  * @param Command $command
  *
  * @return \DOMDocument
  */
 public function getCommandDocument(Command $command)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($commandXML = $dom->createElement('command'));
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $commandXML->setAttribute('id', $command->getName());
     $commandXML->setAttribute('name', $command->getName());
     $commandXML->appendChild($usagesXML = $dom->createElement('usages'));
     foreach (array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()) as $usage) {
         $usagesXML->appendChild($dom->createElement('usage', $usage));
     }
     $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
     $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
     $commandXML->appendChild($helpXML = $dom->createElement('help'));
     $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
     $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
     $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
     return $dom;
 }
 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);
 }
 protected function newJobFound(EntityManager $em, OutputInterface $output, Command $command, CronJobAnno $anno, $defaultDisabled = false)
 {
     $newJob = new CronJob();
     $newJob->setCommand($command->getName());
     $newJob->setDescription($command->getDescription());
     $newJob->setInterval($anno->value);
     $newJob->setNextRun(new \DateTime());
     $newJob->setEnabled(!$defaultDisabled);
     $output->writeln("Added the job " . $newJob->getCommand() . " with interval " . $newJob->getInterval());
     $em->persist($newJob);
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if (!in_array($command->getName(), ['help', 'list'])) {
         $output = new ConsoleOutput($output->getVerbosity(), $output->isDecorated(), $output->getFormatter());
     }
     if ($command instanceof \Cawa\Console\Command) {
         $command->setInput($input);
         $command->setOutput($output);
     }
     return parent::doRunCommand($command, $input, $output);
 }
 /**
  * @param Command  $command
  * @param string[] $arguments
  *
  * @return string
  */
 protected function executeConsole(Command $command, array $arguments = array())
 {
     $command->setApplication(new Application($this->client->getKernel()));
     if ($command instanceof ContainerAwareCommand) {
         $command->setContainer($this->client->getContainer());
     }
     $arguments = array_replace(array('--env' => 'test', 'command' => $command->getName()), $arguments);
     $commandTester = new CommandTester($command);
     $commandTester->execute($arguments);
     return $commandTester->getDisplay();
 }
 /**
  * @inheritdoc
  */
 protected function describeCommand(Command $command, array $options = [])
 {
     $command->getSynopsis();
     $command->mergeApplicationDefinition(false);
     $this->writeText("<comment>Command:</comment> " . $command->getName(), $options);
     $aliases = $command instanceof CommandBase ? $command->getVisibleAliases() : $command->getAliases();
     if ($aliases) {
         $this->writeText("\n");
         $this->writeText('<comment>Aliases:</comment> ' . implode(', ', $aliases), $options);
     }
     if ($description = $command->getDescription()) {
         $this->writeText("\n");
         $this->writeText("<comment>Description:</comment> {$description}", $options);
     }
     $this->writeText("\n\n");
     $this->writeText('<comment>Usage:</comment>', $options);
     $this->writeText("\n");
     $executableName = 'platform';
     $this->writeText(' ' . $executableName . ' ' . $command->getSynopsis(), $options);
     $this->writeText("\n");
     if ($definition = $command->getNativeDefinition()) {
         $this->writeText("\n");
         $this->describeInputDefinition($definition, $options);
         $this->writeText("\n");
     }
     if ($help = $command->getProcessedHelp()) {
         $this->writeText("\n");
         $this->writeText('<comment>Help:</comment>', $options);
         $this->writeText("\n");
         $this->writeText(' ' . str_replace("\n", "\n ", $help), $options);
         $this->writeText("\n");
     }
     if ($command instanceof CommandBase && ($examples = $command->getExamples())) {
         $this->writeText("\n");
         $this->writeText('<comment>Examples:</comment>', $options);
         $name = $command->getName();
         foreach ($examples as $arguments => $description) {
             $this->writeText("\n {$description}:\n   <info>platform {$name} {$arguments}</info>\n");
         }
     }
 }
 public function testConstructor()
 {
     try {
         $command = new Command();
         $this->fail('__construct() throws a \\LogicException if the name is null');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\LogicException', $e, '__construct() throws a \\LogicException if the name is null');
         $this->assertEquals('The command name cannot be empty.', $e->getMessage(), '__construct() throws a \\LogicException if the name is null');
     }
     $command = new Command('foo:bar');
     $this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument');
 }