コード例 #1
0
 /**
  * Test set code.
  *
  * @return void
  *
  * @since  2.0
  */
 public function testSetHandler()
 {
     $this->instance->setHandler(function ($command) {
         return 221;
     });
     $this->assertInstanceOf('\\Closure', $this->instance->getRootCommand()->getHandler(), 'Code need to be a closure.');
     $this->assertEquals(221, $this->instance->getRootCommand()->setIO(new MockIO())->execute());
 }
コード例 #2
0
ファイル: AbstractCommand.php プロジェクト: rokite/windwalker
 /**
  * Write a string to standard output.
  *
  * @param   string   $text  The text to display.
  * @param   boolean  $nl    True (default) to append a new line at the end of the output string.
  *
  * @return  AbstractCommand  Instance of $this to allow chaining.
  *
  * @since   2.0
  */
 public function out($text = '', $nl = true)
 {
     $quiet = $this->app ? $this->app->get('quiet', false) : false;
     if (!$quiet) {
         $this->io->out($text, $nl);
     }
     return $this;
 }
コード例 #3
0
    /**
     * Test describe method.
     *
     * @return void
     *
     * @since  2.0
     */
    public function testDescribe()
    {
        $compare = '<comment>Test Console</comment> - version: 1.2.3
------------------------------------------------------------

[<comment>foo</comment> Help]

foo desc

Usage:
  foo command option


Options:

  <info>-q | --quiet     </info>q desc
  <info>-s | --sakura    </info>sakura desc
  <info>-r               </info>rose desc

Commands:

  <info>aaa    </info>No description
  <info>bar    </info>Bar command desc
  <info>yoo    </info>No description

foo help';
        $console = new Console(new MockIO());
        $console->setName('Test Console')->setVersion('1.2.3')->setDescription('test desc');
        $command = new FooCommand();
        $command->setApplication($console)->description('foo desc')->usage('foo command option')->help('foo help');
        $command->addCommand('bar', 'Bar command desc');
        $command->addCommand('yoo');
        $command->addOption(array('q', 'quiet'), 'default', 'q desc');
        $command->addOption(array('s', 'sakura'), 'default', 'sakura desc');
        $command->addOption(array('r'), 'default', 'rose desc');
        $result = $this->instance->describe($command);
        $this->assertEquals(str_replace("\r\n", "\n", trim($compare)), str_replace("\r\n", "\n", trim($result)));
    }
コード例 #4
0
 /**
  * Class init.
  *
  * @param IOInterface $io
  * @param Registry    $config
  */
 public function __construct(IOInterface $io = null, Registry $config = null)
 {
     restore_error_handler();
     set_error_handler(array($this, 'error'));
     parent::__construct($io, $config);
     $this->registerCommands();
     $this->setDescription('Muse console application.');
     $this->rootCommand->addGlobalOption('p')->alias('path')->description('Dest path.');
     $this->rootCommand->addGlobalOption('t')->alias('tmpl')->defaultValue('default')->description('Sub template name.');
     if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         $this->rootCommand->addGlobalOption('no-ansi', 1, 'Suppress ANSI colors on unsupported terminals.');
     }
     // Set basic dir.
     define('GENERATOR_PATH', $config['basic_dir.base'] ?: realpath(dirname(__DIR__) . '/../..'));
     $this->setHelp('');
 }
コード例 #5
0
    /**
     * Class init.
     *
     * @param   IOInterface $io      The Input and output handler.
     * @param   Registry    $config  Application's config object.
     */
    public function __construct(IOInterface $io = null, \Windwalker\Registry\Registry $config = null)
    {
        $this->loadDispatcher();
        $io = $io ?: $this->getContainer()->get('input');
        // Make Windows no ANSI color
        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
            $io->setOption('ansi', true);
        }
        parent::__construct($io, $config);
        $this->rootCommand->help(<<<HELP
Welcome to Windwalker Console.

HELP
);
        $descriptorHelper = $this->getDescriptor();
        $descriptorHelper->setOptionDescriptor(new OptionDescriptor())->setCommandDescriptor(new CommandDescriptor());
        $this->loadFirstlevelCommands();
    }