當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ConsoleOptionParser::addSubcommand方法代碼示例

本文整理匯總了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;
 }
開發者ID:daoandco,項目名稱:cakephp-cachecleaner,代碼行數:15,代碼來源:ClearShell.php

示例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');
    }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:35,代碼來源:HelpFormatterTest.php

示例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']);
 }
開發者ID:Slayug,項目名稱:castor,代碼行數:21,代碼來源:ShellTest.php

示例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.');
    }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:24,代碼來源:ConsoleOptionParserTest.php


注:本文中的Cake\Console\ConsoleOptionParser::addSubcommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。