本文整理汇总了PHP中Cake\Console\ConsoleOptionParser::addSubcommand方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleOptionParser::addSubcommand方法的具体用法?PHP ConsoleOptionParser::addSubcommand怎么用?PHP ConsoleOptionParser::addSubcommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Console\ConsoleOptionParser
的用法示例。
在下文中一共展示了ConsoleOptionParser::addSubcommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptionParser
/**
* Display help for this console.
*
* @return ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = new ConsoleOptionParser('console');
$parser->description("This shell clean the cache of your application.")->command("cache.clear")->addOption('all', ['short' => 'a', 'help' => 'Clear all caches', 'boolean' => true])->addSubcommand('all', ['help' => 'Clear all caches']);
foreach ($this->tasks as $task => $option) {
$classname = $this->taskClassname($task);
$parser->addSubcommand($this->taskName($task), ['help' => $this->{$classname}->help(), 'parser' => $this->{$classname}->getOptionParser()]);
}
return $parser;
}
示例2: testXmlHelpSubcommand
/**
* test that help() outputs subcommands.
*
* @return void
*/
public function testXmlHelpSubcommand()
{
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addSubcommand('method', ['help' => 'This is another command'])->addOption('test', ['help' => 'A test option.']);
$formatter = new HelpFormatter($parser);
$result = $formatter->xml();
$expected = <<<xml
<?xml version="1.0"?>
<shell>
<name>mycommand</name>
<description/>
<subcommands>
\t<command name="method" help="This is another command" />
</subcommands>
<options>
\t<option name="--help" short="-h" help="Display this help." boolean="1">
\t\t<default></default>
\t\t<choices></choices>
\t</option>
\t<option name="--test" short="" help="A test option." boolean="0">
\t\t<default></default>
\t\t<choices></choices>
\t</option>
</options>
<arguments/>
<epilog/>
</shell>
xml;
$this->assertXmlStringNotEqualsXmlString($expected, $result, 'Help does not match');
}
示例3: testRunCommandHittingTaskInSubcommand
/**
* test that runCommand will call runCommand on the task.
*
* @return void
*/
public function testRunCommandHittingTaskInSubcommand()
{
$parser = new ConsoleOptionParser('knife');
$parser->addSubcommand('slice');
$io = $this->getMock('Cake\\Console\\ConsoleIo');
$shell = $this->getMock('Cake\\Console\\Shell', ['hasTask', 'startup', 'getOptionParser'], [], '', false);
$shell->io($io);
$task = $this->getMock('Cake\\Console\\Shell', ['main', 'runCommand'], [], '', false);
$task->io($io);
$task->expects($this->once())->method('runCommand')->with(['one'], false);
$shell->expects($this->once())->method('getOptionParser')->will($this->returnValue($parser));
$shell->expects($this->once())->method('startup');
$shell->expects($this->any())->method('hasTask')->will($this->returnValue(true));
$shell->Slice = $task;
$shell->runCommand(['slice', 'one']);
}
示例4: testHelpSubcommandHelp
/**
* test that help() with a command param shows the help for a subcommand
*
* @return void
*/
public function testHelpSubcommandHelp()
{
$subParser = new ConsoleOptionParser('method', false);
$subParser->addOption('connection', ['help' => 'Db connection.']);
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addSubcommand('method', ['help' => 'This is another command', 'parser' => $subParser])->addOption('test', ['help' => 'A test option.']);
$result = $parser->help('method');
$expected = <<<TEXT
<info>Usage:</info>
cake mycommand method [-h] [--connection]
<info>Options:</info>
--help, -h Display this help.
--connection Db connection.
TEXT;
$this->assertTextEquals($expected, $result, 'Help is not correct.');
}