getArgsFormat() public method

Returns the arguments format of the command.
public getArgsFormat ( ) : ArgsFormat
return Webmozart\Console\Api\Args\Format\ArgsFormat The input definition.
コード例 #1
0
 public function testRenderApplicationJson()
 {
     $args = new Args($this->helpCommand->getArgsFormat());
     $status = $this->handler->handle($args, $this->io, $this->command);
     $this->assertStringStartsWith('{"commands":[{"name":"help",', $this->io->fetchOutput());
     $this->assertSame(0, $status);
 }
コード例 #2
0
    public function testRenderApplicationXml()
    {
        $args = new Args($this->helpCommand->getArgsFormat());
        $status = $this->handler->handle($args, $this->io, $this->command);
        $expected = <<<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<symfony name="The Application" version="1.2.3">
EOF;
        $this->assertStringStartsWith($expected, $this->io->fetchOutput());
        $this->assertSame(0, $status);
    }
コード例 #3
0
    public function testRenderApplicationText()
    {
        $args = new Args($this->helpCommand->getArgsFormat());
        $status = $this->handler->handle($args, $this->io, $this->command);
        $expected = <<<'EOF'
The Application version 1.2.3

USAGE
  console
EOF;
        $this->assertStringStartsWith($expected, $this->io->fetchOutput());
        $this->assertSame(0, $status);
    }
コード例 #4
0
ファイル: Command.php プロジェクト: webmozart/console
 /**
  * Returns the inherited arguments format of the command.
  *
  * @return ArgsFormat The inherited format.
  *
  * @see CommandConfig::buildArgsFormat()
  */
 private function getBaseFormat()
 {
     if ($this->parentCommand) {
         return $this->parentCommand->getArgsFormat();
     }
     if ($this->application) {
         return $this->application->getGlobalArgsFormat();
     }
     return null;
 }
コード例 #5
0
 public function testCreate()
 {
     $config = CommandConfig::create()->setName('command')->addAlias('alias1')->addAlias('alias2')->setDescription('Description of the command')->setHelp('The help for %command.name%')->addArgument('argument')->addOption('option', 'o')->setHelperSet($helperSet = new HelperSet());
     $applicationConfig = new ApplicationConfig();
     $application = new ConsoleApplication($applicationConfig);
     $applicationAdapter = new ApplicationAdapter($application);
     $command = new Command($config, $application);
     $adapter = new CommandAdapter($command, $applicationAdapter);
     $this->assertSame('command', $adapter->getName());
     $this->assertEquals(new ArgsFormatInputDefinition($command->getArgsFormat()), $adapter->getDefinition());
     $this->assertEquals(new ArgsFormatInputDefinition($command->getArgsFormat()), $adapter->getNativeDefinition());
     $this->assertSame($command, $adapter->getAdaptedCommand());
     $this->assertSame(array('alias1', 'alias2'), $adapter->getAliases());
     $this->assertSame($applicationAdapter, $adapter->getApplication());
     $this->assertSame('Description of the command', $adapter->getDescription());
     $this->assertSame('The help for %command.name%', $adapter->getHelp());
     $this->assertSame('The help for command', $adapter->getProcessedHelp());
     $this->assertSame($helperSet, $adapter->getHelperSet());
     $this->assertSame('command [-o|--option] [--] <cmd1> [<argument>]', $adapter->getSynopsis());
     $this->assertTrue($adapter->isEnabled());
 }
コード例 #6
0
ファイル: CommandHelp.php プロジェクト: webmozart/console
 /**
  * Renders a sub-command in the "Commands" section.
  *
  * @param BlockLayout $layout  The layout.
  * @param Command     $command The command to render.
  */
 protected function renderSubCommand(BlockLayout $layout, Command $command)
 {
     $config = $command->getConfig();
     $description = $config->getDescription();
     $help = $config->getHelp();
     $arguments = $command->getArgsFormat()->getArguments(false);
     $options = $command->getArgsFormat()->getOptions(false);
     if ($config instanceof OptionCommandConfig) {
         if ($config->isLongNamePreferred()) {
             $preferredName = '--<u>' . $config->getLongName() . '</u>';
             $alternativeName = $config->getShortName() ? '-<u>' . $config->getShortName() . '</u>' : null;
         } else {
             $preferredName = '-<u>' . $config->getShortName() . '</u>';
             $alternativeName = '--<u>' . $config->getLongName() . '</u>';
         }
         $name = $preferredName;
         if ($alternativeName) {
             $name .= ' (' . $alternativeName . ')';
         }
     } else {
         $name = '<u>' . $command->getName() . '</u>';
     }
     $layout->add(new Paragraph($name));
     $layout->beginBlock();
     if ($description) {
         $this->renderSubCommandDescription($layout, $description);
     }
     if ($help) {
         $this->renderSubCommandHelp($layout, $help);
     }
     if ($arguments) {
         $this->renderSubCommandArguments($layout, $arguments);
     }
     if ($options) {
         $this->renderSubCommandOptions($layout, $options);
     }
     if (!$description && !$help && !$arguments && !$options) {
         $layout->add(new EmptyLine());
     }
     $layout->endBlock();
 }
コード例 #7
0
ファイル: CommandTest.php プロジェクト: webmozart/console
 public function testRunWithLenientArgsParsing()
 {
     $rawArgs = $this->getMock('Webmozart\\Console\\Api\\Args\\RawArgs');
     $parsedArgs = new Args(new ArgsFormat());
     $io = $this->getMockBuilder('Webmozart\\Console\\Api\\IO\\IO')->disableOriginalConstructor()->getMock();
     $parser = $this->getMock('Webmozart\\Console\\Api\\Args\\ArgsParser');
     $handler = $this->getMock('stdClass', array('handle'));
     $config = new CommandConfig('command');
     $config->setArgsParser($parser);
     $config->setHandler($handler);
     $config->enableLenientArgsParsing();
     $command = new Command($config);
     $format = $command->getArgsFormat();
     $parser->expects($this->once())->method('parseArgs')->with($this->identicalTo($rawArgs), $this->identicalTo($format), true)->willReturn($parsedArgs);
     $handler->expects($this->once())->method('handle')->with($parsedArgs, $io, $command)->willReturn(123);
     $this->assertSame(123, $command->run($rawArgs, $io));
 }