slk/icm

交互式命令行标记语言

资助包维护!
社区桥梁

安装数量: 5,437

依赖项: 1

建议者: 0

安全: 0

星星: 2

关注者: 2

分支: 0

开放性问题: 0

类型:项目

dev-master 2015-08-12 11:36 UTC

This package is auto-updated.

Last update: 2024-09-14 01:12:02 UTC


README

交互式命令行标记语言(ICM)

ICM 的创建是为了让您能够轻松地为您的命令行程序创建交互式教程,类似于 Redis(《http://try.redis.io》)或 Docker(《https://www.docker.io/gettingstarted/》)的交互式教程。

安装

在 require compose.json 部分添加以下行

"slk/icm" : "dev-master"

之后,在您的 PHP 应用程序中,您可以使用 Slk\View\ICMRenderer。

标记语言

提示

To prompt the user input you can add in the beginning of a line the following 

>_

To prompt for user output and show also the name of the command line program use:

>$_

The sequence below can be used to check against the user input against expected value:

>$_
==--help

That above two lines will create a prompt with the name of the current program and will expect
from the user to enter --help

You can also use also regular experession for input matching

>$_
==/\s*\-\-help\s*/

The command above will check if the user entered --help with or without trailing spaces.

If the expected input from the user is difficult for him to guess you can add an example. 

>$_
==/\s*command\s+\-\-help\s*/
===command --help

And finally if you want to save the user input you can store it in a variable with a name

>$_
==/\s*command\s+\-\-help\s*/
===command --help
=> input

The above three lines will ask the user for an input, he has to answer with "command --help" or will be shown the 
example at the end and the input of the user will be saved in a variable with the name input.


Command exection

要向当前控制台行程序传递参数并执行它们,可以使用以下语法

$_ xyz

这将执行 " xyz",结果将保存在名为 "result" 的变量中。

变量

Variables are describe in the same way that you do in PHP. There is one pre-defined variable $script that contains
the full name of the command line application that is currently executed.

After command execution with $_ the result is saved in $result. 
The input from a promt can be saved in a named variable that can be used later on. 

>$_
==/\s*command\s+\-\-help\s*/
===command --help
=> input

In the example above after these four lines are executed you can get the info by reading $input. 

Page breaks

如果您的行以三个或更多短横线(-)开头,则会提示用户按回车键继续。如果您有三个或更多大于号(>)符号,则会提示用户按回车键进入下一页。在命令行上下文中,进入下一页意味着清除当前屏幕。