1 Star 3 Fork 26

yg178/php-console

forked from inhere/php-console 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DemoCommand.php 2.34 KB
一键复制 编辑 原始数据 按行查看 历史
inhere 提交于 2018-01-24 10:02 +08:00 . update demo description. add changelog file
<?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
);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/hwsyy/php-console.git
git@gitee.com:hwsyy/php-console.git
hwsyy
php-console
php-console
master

搜索帮助