yalesov/zf2-cli
Composer 安装命令:
composer require yalesov/zf2-cli
包简介
helper functions for building a zf2 CLI app
README 文档
README
helper functions for building a zf2 CLI app
Installation
{
"require": {
"yalesov/zf2-cli": "2.*"
}
}
Copy config/cli.local.php.dist into (app root)/config/autoload/cli.local.php, and edit configs as described below in Setup templates.
Usage
Get an instance of cli
Use service locator.
$cli = $locator->get('cli'); $cli = $locator->get('Yalesov\Cli\Cli');
Or just instantiate one manually.
$cli = new \Yalesov\Cli\Cli;
Templated-text
Often you need to display similarly-formatted text in a CLI app, e.g. section titles.
Setup templates
Add a template named section, which outputs a blue string ## %s ## (%s replaced by actual text).
$cli->addTemplate('section', array( 'template' => '## %s ##', 'color' => 'BLUE', ));
template: (optional),%sas text placeholder; not set ='%s'(plain text)color: (optional), a\Zend\Console\ColorInterfacedefined constant name; not set = default / normal color
You can also inject templates through the config file:
return array( 'di' => array( 'instance' => array( 'alias' => array( 'cli' => 'Yalesov\Cli\Cli', ), 'cli' => array( 'parameters' => array( 'templates' => array ( 'section' => array( 'template' => '## %s ##', 'color' => 'YELLOW', ), 'task' => array ( 'template' => '- %s -', 'color' => 'BLUE', ), 'module' => array( 'template' => '[ %s ]', 'color' => 'GREEN', ), ), ), ), ), ), );
This will setup the templates section, task, and module.
Output text
$cli->write('foo', 'section');
This will output the string foo using the section template. In the above example setup, this will output ## foo ##, with yellow color.
You can also capture the output string instead of printing it directly:
$string = $cli->write('foo', 'section', false);
统计信息
- 总下载量: 94
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2016-07-05