代码拉取完成,页面将自动刷新
同步操作将从 inhere/php-console 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
/**
* Created by PhpStorm.
* User: inhere
* Date: 2017-02-27
* Time: 18:58
*/
namespace Inhere\Console\Examples\Commands;
use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
/**
* Class DemoCommand
* @package Inhere\Console\Examples\Commands
*/
class DemoCommand extends Command
{
protected static $name = 'demo';
protected static $description = 'this is a demo alone command. but config use configure(), like symfony console: argument define by position';
/**
* {@inheritDoc}
* @throws \LogicException
*/
protected function configure()
{
$this->createDefinition()
->setDescription(self::getDescription())
->setExample($this->parseAnnotationVars('{script} {command} john male 43 --opt1 value1'))
->addArgument('name', Input::ARG_REQUIRED, 'description for the argument [name], is required')
->addArgument('sex', Input::ARG_OPTIONAL, 'description for the argument [sex], is optional')
->addArgument('age', Input::ARG_OPTIONAL, 'description for the argument [age], is optional')
->addOption('yes', 'y', Input::OPT_BOOLEAN, 'description for the option [yes], is boolean')
->addOption('opt1', null, Input::OPT_REQUIRED, 'description for the option [opt1], is required')
->addOption('opt2', null, Input::OPT_OPTIONAL, 'description for the option [opt2], is optional')
;
}
/**
* description text by annotation. it is invalid when configure() is exists
* @param Input $input
* @param Output $output
* @return int|void
*/
public function execute($input, $output)
{
$output->write('hello, this in ' . __METHOD__);
// $name = $input->getArg('name');
$output->write(<<<EOF
this is argument and option example:
the opt1's value
option: opt1 |
| |
php examples/app demo john male 43 --opt1 value1 -y
| | | | | |
script command | | |______ option: yes, it use shortcat: y, and it is a Input::OPT_BOOLEAN, so no value.
| |___ |
argument: name | argument: age
argument: sex
EOF
);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。