eftec/clione

用于Windows和Linux的PHP命令行(CLI)生成器

1.35 2024-09-23 12:21 UTC

README

此库帮助在Windows、Mac和Linux上为PHP创建命令行(CLI)操作员

Packagist Total Downloads Maintenance composer php php CocoaPods

功能

✅ 兼容Windows、Linux和Mac。

✅ 该库真正极简和简单,它仅由2个类组成,没有其他东西,也没有外部依赖。

✅ 参数和用户输入

✅ 该库旨在(可选)在参数缺失时回退到用户输入。

✅ 可用颜色

✅ 设计大多流畅(它调整到屏幕宽度)

✅ 值验证

✅ 支持 NO_COLOR 环境变量。请参阅https://no-color.org/

入门

使用Composer添加库

composer require eftec/clione

创建库的新实例

$cli=new CliOne(); // instance of the library

用法

例如,假设我们需要创建一个CLI代码来读取信息并将其保存到文件中。

>php basic.php read -o result.json

我们有两个参数,第一个(read)位于第一个位置,它没有任何"-"。第二个是"-o",它是我们的带值的标志。

因此我们可以创建我们的参数。

$cli=new CliOne();
$cli->createParam('read',[],'first')->add(); // a positional argument (the first one) value-less
$cli->createParam('o',[],'flag')->add(); // a simple flag "-o"

然后我们可以评估为

$cli->evalParam('read');
$cli->evalParam('o');
// So we could obtain our values as:
var_dump($cli->getParameter('read')->value); 
var_dump($cli->getParameter('o')->value);
// or as
var_dump($cli->getValue('read'));
var_dump($cli->getValue('o'));

如果没有设置值,则返回false,如果设置了值,则返回该值。

>php basic.php read -o result.json
string(4) "read"
string(11) "result.json"

参数是分别创建和评估的,因为这允许对其进行更强大的操作。

例如,有时我们想在不需要评估参数的情况下显示帮助(可用参数的列表)。

好的,但现在如果我们想为"-o"创建别名怎么办?

var_dump($cli->getParameter('o',['output','outputresult'])->value);

因此我们可以使用此行调用

php basic.php read --output result.json
# or also
php basic.php read --outputresult result.json
# or also
php basic.php read -o=result.json

如果参数是标志,则别名是长标志("--")。如果参数是长标志,则别名是标志。

但让我们假设我们需要请求密码,但我们希望它交互式输入。

$cli->createParam('pwd',[],'flag') // we create the parameter
    ->setInput(true,'password') // and we ask (if the parameter is not entered as flag) 
                                //for user input of the type password (however the password is not hidden visually)
    ->add();
$cli->evalParam('pwd');   // and don't forget to evaluate the parameter

所以它看起来像这样

> php .\basic.php read -o result.json
Select the value of pwd [*****] :123

现在,让我们做一个更高级的例子,多个选项,我们想要选择文件类型:json、csv、html和xml

我们的代码

$cli->createParam('type',[],'flag')
    ->setInput(true,'option',['json','csv','xml','html'])
    ->add();

结果是

PS > php .\basic.php read -o result.json
Select the value of pwd [*****] :111
[1] json                     
[2] csv                      
[3] xml                      
[4] html                     
Select the value of type [] :2 #you could use TAB key for autocomplete, cool!

值列表分为两个值,一个是可视值(简单地称为value),另一个是键值。。在这个例子中,"csv"是一个值,它的键值是"2"。

值列表允许关联数组和索引数组。索引数组将重新编号以从1开始。

您也可以输入

php .\basic.php read -o result.json -pwd 123 -type json

现在,您可以通过以下方式显示参数(显示语法帮助)

$cli->showParamSyntax2('parameters:');

但它看起来很普通。

这是因为您可以添加描述,更改问题并添加更多帮助信息

$cli->createParam('type',[],'flag')
    ->setDescription('it is the type of output','what is the option?',['it is the help1','example: -option xml'])
    ->setInput(true,'option',['json','csv','xml','html'])
    ->add();

所以它看起来会这样:(带颜色)

parameters:
read                         The command [read]
-o, --output, --outputresult The output file without extension [result.json]
                             example: -o file
-pwd                         It is the password [*****]
-type                        it is the type of output [csv]
                             it is the help1
                             example: -option xml

还有更多操作可用,但基本功能都在那里。

目录

流程

  • (可选)可以使用 setParam() 方法设置当前值
  • 如果参数类型不是 "onlyinput" 和 "none",则读取参数
    • 示例:php program.php -param1 value --param2 -param3="hello world" 参数位置
  • 如果找到参数,则返回,流程结束
  • 如果未找到参数
    • 如果设置 setCurrentAsDefault(),并且当前值不为空,则默认值是当前值。
    • 否则,默认值是使用 setDefault() 方法设置的值。如果没有设置,则使用 null。
  • 如果输入为真,则 setInput(true),然后要求用户输入值
    • 如果用户没有填写信息,则返回默认值(如果有),流程结束
    • 如果用户填写了信息,但信息不正确,则反复要求。
    • 如果用户填写了正确的信息,则返回此值,流程结束
  • 如果输入为真,则调用 setInput(false)。
    • 注意:我们无法读取参数的值,并且我们不希望从用户输入中读取。
    • 它返回默认值,可能会引发错误,结束流程

注意

  • 如果 isRequired() 检测到值缺失,则显示错误。
  • 如果 setAllowEmpty(),则当值是空的(非缺失)时,允许输入空值。

作为参数输入

php mycli.php subcommandfirst subcommandsecond -flag valueflag --longflag valueflag2 subcommandlatest

系统允许读取多种类型的参数

  • 第一个:此参数没有值,并且它是位置(在第一个位置),它必须不以 "-" 为前缀,否则它将被视为标志而不是位置参数。
cliprogram.php first # the value obtained is "first".
  • 命令:它与 第一个 类似,但它不比较参数的名称。
cliprogram.php com -flag # first returns "com" if the argument is named first.  command returns "com" regardless of its name.
  • 第二个:此参数也是位置(第二个位置)且没有值。
cliprogram.php first second -someflag # the value obtained is "second"
  • 最后一个:此参数也是位置参数,并且它始终是最后一个参数。
cliprogram.php first second  last # the value obtained is "last"
  • 标志:参数以单个 "-" 为前缀。此参数不需要是单个字符。
cliprogram.php -flag hello # the value of the flag called "flag" is "hello"
  • 长标志:参数以双 "-" 为前缀。
cliprogram.php --flag hello # the value of the doubleflag called "flag" is "hello"
  • 只输入/无:系统永远不会将其视为参数,因此它可以来自用户输入。
    • 无意味着参数仅来自用户输入,且不应被存储。
cliprogram.php  # "onlyinput/none" could not be obtained via command line

参数可以创建为

// program.php -f hello
// or
// program.php -f=hello
// or
// program.php -f "hello world"
$cli->createParam('f','flag')->add();  // add() is important otherwise the parameter will not be create.

并且可以读取为

$result=$cli->evalParam('name'); // $result->value will return "hello"

现在,如果你想要为同一参数创建多个别名。

// program.php -h 
// or
// program.php --help 
$cli->createParam('h','flag',['help'])->add();  // it adds an alias longflag called "help"

交互式输入

有几种配置可以交互式地设置输入。

默认情况下,每个参数都作为参数读取。如果值被读取为参数,则不会进行交互式询问。

然而,如果参数的类型是 "" 或 "只输入",则它们仅通过用户输入(交互式)获得。

示例

$cli->$t->createParam('paramname',[],'none');

用户输入(交互式)

使用 setInput() 方法,我们可以设置该参数也可以被交互式读取。

$cli->$t->createParam('paramname',[],'none')->setInput();

示例,让我们看下面的例子

$cli=new CliOne();
$cli->createParam('p1',[],'none')
    ->setInput()
    ->add(); // we create the param
$cli->evalParam('p1'); // and we evaluated the parameter

现在,这个输入接受任何类型的文本。但是有各种用户输入。

Option 返回一个值和一个值键。值是可见的内容。值键是用户选择的内容。

示例 Option

$cli=new CliOne();
$cli->createParam('p1',[],'none')
    ->setInput(true,'option2',['key1'=>'value1','key2'=>'value2','key3'=>'value3','key4'=>'value4'])
    ->add(); // we create the param
$cli->evalParam('p1');
$cli->showLine("value :".$cli->getValue('p1'));
$cli->showLine("valuekey :".$cli->getValueKey('p1'));

示例 多个

$cli=new CliOne();
$cli->createParam('p1',[],'none')
    ->setInput(true,'option2',['key1'=>'value1','key2'=>'value2','key3'=>'value3','key4'=>'value4'])
    ->add(); 
$cli->evalParam('p1'); // value returns an associative array with the values selected, example: ["value1","value3"]

自定义用户输入

可以通过更改帮助描述、更改问题、显示示例或显示值到参数来自定义输入。

$cli=new CliOne();
$cli->createParam('p1',[],'none')
    ->setInput()
    ->setDescription('it is for help','what is the value of p1?',['help line1','help line 2'],'the argument is called p1')
    ->add(); 
$cli->evalParam('p1'); 

CliOne类

CliOne - 一个简单的命令行参数程序创建器。

方法 __construct()

构造函数。如果有实例,则它将替换实例。

参数

  • $origin 你可以指定原始脚本文件。如果你指定了原始脚本,则 isCli 仅在文件直接使用其文件名调用时返回 true。(字符串或 null)
  • $ignoreCli 如果为 true,则无论是否在 cli 上运行,它都将运行。(布尔值)

方法 getWindowsVersion()

它返回当前 Windows 版本作为十进制数字。
如果没有找到版本,则返回 6.1(Windows 7)。
Windows 10 和 Windows 11 版本以 10.xxxx 返回,而不是 10.0.xxxx

方法 instance()

它获取库的当前实例。
如果实例不存在,则创建它。

参数

  • $origin 你可以指定原始脚本文件。如果你指定了原始脚本,则 isCli 仅在文件直接使用其文件名调用时返回 true。(字符串或 null)

方法 hasInstance()

如果存在 CliOne 的实例,则返回 true。

方法 hasMenu()

如果 CliOne 有定义菜单,则返回 true。如果没有菜单或没有实例,则返回 false。

方法 clearMenu()

它清除菜单及其关联的服务。

参数

  • $idMenu 如果为 null,则清除所有菜单(字符串或 null)

方法 addMenu()

它添加一个新菜单,该菜单可以通过 evalMenu() 调用。
示例

//"fnheader" call to $this->menuHeader(CliOne $cli);
$this->addMenu('idmenu','fnheader',null,'What do you want to do?','option3');
// you can use a callable argument, the first argument is of type CliOne.
$this->addMenu('idmenu',function($cli) { echo "header";},function($cli) { echo "footer;"});

参数

  • $idMenu 菜单的唯一名称(字符串)
  • $headerFunction 可选,每次菜单显示时调用的方法的名称
    必须调用的方法必须有一个前缀菜单。例如:"opt1",方法:"menuopt1"。如果 $headerFunction 是可调用的,则调用该函数。(字符串|null|可调用)
  • $footerFunction 可选的,每次菜单结束显示时调用的方法名称。调用的方法必须以 "menu" 为前缀。
    如果 $footerFunction 是可调用的,则调用该函数(字符串|null|可调用)
  • $question 输入问题。(字符串)
  • $size =['option','option2','option3','option4','wide-option','wide-option2'][$i] 选项菜单的大小。(字符串)

方法 addMenuItem()

它添加一个菜单项。
示例

$this->addMenu('menu1');
// if op1 is selected then it calls method menufnop1(), the prefix is for protection.
$this->addMenuItem('menu1','op1','option #1','fnop1');
// if op1 is selected then it calls method menuop2()
$this->addMenuItem('menu1','op2','option #2');
$this->addMenuItem('menu1','op3','go to menu2','navigate:menu2');
$this->addMenuItem('menu1','op4','call function',function(CliOne $cli) {  });
$this->evalMenu('menu1',$obj);
// the method inside $obj
public function menufnop1($caller):void {
}
public function menuop2($caller):string {
return 'EXIT'; // if any function returns EXIT (uppercase), then the menu ends (simmilar to "empty to
exit")
}

参数

  • $idMenu 菜单的唯一名称(字符串)
  • $indexMenuItem 菜单的唯一索引。它用于选择和动作(如果没有提供动作)。(字符串)
  • $description 菜单的描述(字符串)
  • $action 动作是调用的方法(方法必须以 "menu" 为前缀)。
    如果动作以 "navigate:" 开头,则打开指定的菜单。
    如果动作是 "exit:",则退出菜单。
    如果动作是可调用的,则调用该函数(字符串|null|可调用)

方法 addMenuItems()

向菜单添加多个项。
示例

$this->addMenu('menu1');
$this->addMenuItems('menu1',[
'op1'=>['operation #1','action1'], // with description & action
'op2'=>'operation #2']); // the action is "op2"

参数

  • $idMenu 菜单的唯一名称(字符串)
  • $items 一个关联数组,包含要添加的项。示例
    [index=>[description,action]]
    [index=>description]
    (数组|null)

方法 addMenuService()

在运行 evalMenu() 时评估要评估的服务对象。
您可以添加菜单服务。每个服务按顺序评估,所以如果两个服务对象具有相同的方法,则只有第一个对象被调用。
如果 evalMenu() 使用服务,则忽略此处定义的服务。
示例

$objService=new Class1();
$this->addMenuService('menu1',$objService);
// or:
$this->addMenuService('menu1',Class1:class);

参数

  • $idMenu 菜单的唯一名称(字符串)
  • $service 服务对象或类的名称。
    如果是类的名称,则创建其实例。(对象|字符串)

方法 evalMenu()

评估(执行)之前定义的菜单。
示例

$this->addMenu('menu1');
// pending: add items to the menu
$this->evalMenu('menu1',$myService);
// or also
$this->>addMenu('menu1')->addMenuService('menu1',$myService)->evalMenu('menu1');

参数

  • $idMenu 菜单的唯一名称(字符串)
  • $caller 调用者对象。它用于事件和动作。
    如果为 null,则使用 addMenuService() 定义的服务。
    如果它是一个数组,则调用具有该方法的第一对象。
    如果使用此参数,则忽略 addMenuService()(对象|null|数组)

方法 getErrorType()

方法 getMemory()

方法 setVariable()

将值设置到数组中。

参数

  • $variableName 变量的名称。如果变量存在,则替换它。(字符串)
  • $value 要分配的值。(混合类型)
  • $callBack 如果值为 true(默认值),则每次修改(如果值已更改)都会调用在 addVariableCallBack() 中定义的函数。
    如果为 false,则不会调用回调函数。(布尔类型)

方法 getVariable()

获取变量的值。

参数

  • $variableName 变量的名称(字符串)
  • $valueIfNotFound 如果未找到,则返回此值(混合类型|null)

方法 addVariableCallBack()

添加回调函数。
示例

$t->addVariableCallBack('call1', function(CliOne $cli) {
$cli->setVariable('v2', 'world',false); // the false is important if you don't want recursivity
});

此函数在每次 setVariable() 时调用,如果值与定义的不同。

参数

  • $callbackName 函数的名称。如果函数存在,则替换它(字符串)
  • $function 如果函数为 null,则删除分配的函数。
    函数可以使用类型为 CliOne 的参数定义。(可调用型|null)

方法 callVariablesCallBack()

调用回调函数。通常它们在每次 setVariable()(并且值已更改)时调用。

方法 hasColorSupport()

此函数基于 Symfony。

方法 testArguments()

它用于测试。您可以使用此函数模拟参数。
此函数必须在创建实例之前调用。

参数

  • $arguments 参数数组 $arguments(数组)

方法 testUserInput()

它用于测试。您可以使用此函数模拟用户输入。
此函数必须在每次交互之前调用。
此函数不会自动重置,要重置它,设置 $userInput=null。

参数

  • $userInput 参数 ?array $userInput (?array)
  • $throwNoInput (def:true) 如果为真,则在没有输入时抛出异常
    如果为假,那么如果没有更多输入,则清理用户输入(布尔值)

方法 setMemory()

它将值存储到内存流中
如果内存流中有值,则删除并替换它们。

参数

  • $memory 要存储的值(字符串)

方法 setErrorType()

它设置是否显示错误。每次使用时都会重置此标志。

参数

  • $errorType =['silent','show','throw'][$i](默认为 show)(字符串)

方法 findVendorPath()

它从路由开始查找供应商路径。路由必须位于应用程序路径内部。

参数

  • $initPath 初始路径,例如 DIR,getcwd(),'folder1/folder2'。如果为空,则 DIR (?字符串)

方法 createParam()

它创建一个新的参数,可以从命令行读取,也可以由用户手动输入
示例

$this->createParam('k1','first'); // php program.php thissubcommand
$this->createParam('k1','flag',['flag2','flag3']); // php program.php -k1 <val> or --flag2 <val> or --flag3
<val>

参数

  • $key 键或参数。它必须是唯一的。(字符串)
  • $alias 一个简单的数组,包含要读取的参数名称,不带 "-" 或 标志:(默认)它读取标志 "php program.php -thisflag value"
    first:读取第一个参数 "php program.php thisarg"(不带值)
    second:读取第二个参数 "php program.php sc1 thisarg"(不带值)
    last:读取第二个参数 "php program.php ... thisarg"(不带值)
    longflag:读取长标志 "php program --thislongflag value
    last:读取第二个参数 "php program.php ... thisvalue"(不带值)
    onlyinput:值表示用户输入,并将其存储
    none:值不是通过参数捕获的,因此它可以是用户输入,但它不会被存储
    没有参数可以始终被覆盖,并且它们用于“临时”输入,例如验证(y/n)。(数组|字符串)
  • $type =['command','first','last','second','flag','longflag','onlyinput','none'][$i]
    "-"
    如果类型是标志,则别名是双标志"--"。
    如果类型是双标志,则别名是标志。(字符串)
  • $argumentIsValueKey true 参数是值键
    false(默认)参数是值(布尔值)

方法 createOrReplaceParam()

方法 downLevel()

在面包屑中下移一个级别。
如果下移的级别超过可用的级别数,则清除堆栈。

参数

  • $number 要下移的级别数。(整数)

方法 evalParam()

它评估从命令语法中获得的参数。
在调用此方法之前必须定义参数。
示例

// shell:
php mycode.php -argument1 hello -argument2 world
// php code:
$t=new CliOne('mycode.php');
$t->createParam('argument1')->add();
$result=$t->evalParam('argument1'); // an object ClieOneParam where value is "hello"

参数

  • $key 要读取的键。
    如果 $key='*',则读取第一个标志并返回其值(如果有)。(字符串)
  • $forceInput 强制输入,无论值是否已插入。
  • $returnValue 如果为真,则返回获得的值。
    如果为假(默认值),则返回 CliOneParam 的实例。(布尔值)

方法 throwError()

它抛出一个错误。根据类型,它可能显示错误或抛出运行时异常。

参数

  • $msg 参数字符串 $msg(字符串)

方法 showWarning()

它显示一个警告

参数

  • $msg 参数数组|string $msg(数组|string)

方法 addHistory()

向历史记录添加一个值

参数

  • $prompt 要添加的历史记录值(字符串|数组)

方法 setHistory()

它使用新值设置历史记录(删除旧历史记录)

参数

  • $prompt 参数字符串|array $prompt(字符串|数组)

方法 clearHistory()

它清除全局历史记录(如果有的话)。

方法 listHistory()

它检索全局历史记录(如果有的话)

方法 getArrayParams()

它返回一个关联数组,包含所有表单参数 [key=>value]
忽略类型为 "none" 的参数

参数

  • $excludeKeys 您可以添加要排除的键。(数组)

方法 getColSize()

它返回屏幕上存在的列数。列数在构造函数中计算。

方法 getParameter()

通过键或空参数(键为null)获取参数。

参数

  • $key 参数的键(字符串)

方法 getValue()

读取参数的值。示例:

// [1] option1
// [2] option2
// select a value [] 2
$v=$this->getValueKey('idparam'); // it will return "option2".

参数

  • $key 要读取值的参数的键(字符串)

方法 readArgument()

读取参数作为参数或标志。

参数

  • $parameter 参数 CliOneParam $parameter(CliOneParam)

方法 showHelp()

显示帮助

参数

  • $parameter 参数 CliOneParam $parameter(CliOneParam)
  • $verbose 参数 bool $verbose(布尔值)

方法 makeBigWords()

参数

  • $word 要显示的单词。(字符串)
  • $font =['atr','znaki'][$i](字符串)
  • $trim 如果为true,则,如果第一行和/或最后一行是空的,则将其删除。(布尔值)
  • $bit1 可见字符,如果为null,则使用块代码(字符串)
  • $bit0 不可见字符(字符串)

方法 getValueKey()

读取选定的参数的值-键。对于元素列表非常有用。
示例

// [1] option1
// [2] option2
// select a value [] 2
$v=$this->getValueKey('idparam'); // it will return 2 instead of "option2"

参数

  • $key 要读取值-键的参数的键(字符串)

方法 isCli()

如果PHP在CLI上运行,则返回true。
如果构造函数指定了文件,则它也用于验证。示例:

// page.php:
$inst=new CliOne('page.php'); // this security avoid calling the cli when this file is called by others.
if($inst->isCli()) {
echo "Is CLI and the current page is page.php";
}

方法 getSTDIN()

如果通过管道传递值,则获取STDIN的独占访问。否则,返回null;

方法 readData()

从文件读取信息。信息将被反序列化。

参数

  • $filename 文件名,带或不带扩展名。(字符串)
  • $defaultExtension 默认扩展名。(字符串)

方法 readDataPHPFormat()

从文件读取信息。信息将被评估,因此文件必须安全。

参数

  • $filename 文件名,带或不带扩展名。(字符串)
  • $defaultExtension 默认扩展名。(字符串)

方法 isParameterPresent()

如果参数存在,无论是否包含数据,则返回true。
参数未更改,默认值或用户输入均未应用
返回值

  • none 值不存在,例如
  • empty 值存在但为空,例如:-arg1
  • value 值存在,并且具有值,例如:-arg1 value

参数

  • $key 参数字符串 $key(字符串)

方法 addExtensionFile()

实用类。仅在文件名没有扩展名时向文件名添加默认扩展名。

参数

  • $filename 完整或部分文件名,例如 "file.jpg","file","/folder/file"(字符串)
  • $extension 要添加的扩展名,包括点,例如 ".ext"。(字符串)
    默认值是 ".config.php"(字符串)

方法 saveData()

将信息保存到文件中。内容将被序列化。

参数

  • $filename 要保存值的文件名(不带扩展名)。(字符串)
  • $content 要保存的内容。它将被序列化。(混合类型)
  • $defaultExtension 默认扩展名。(字符串)

方法 saveDataPHPFormat()

将信息保存到文件中。内容将被转换为PHP文件。
示例

$this->saveDataPHPFormat('file',[1,2,3]); // it will save a file with the next content: $config=[1,2,3];

参数

  • $filename 要保存值的文件名(不带扩展名)。(字符串)
  • $content 要保存的内容。它将被序列化。(混合类型)
  • $defaultExtension 默认扩展名。(字符串)
  • $namevar 变量名,例如:config或 $config(字符串)

方法 setAlign()

设置对齐。此方法可堆叠。
示例

$cli->setAlign('left','left','right')->setStyle('double')->showTable($values);

参数

  • $title =['left','right','middle'][$i] 标题的对齐(字符串)
  • $content =['left','right','middle'][$i] 内容的对齐(字符串)
  • $contentNumeric =['left','right','middle'][$i] 内容的对齐(数值)(字符串)

方法 setArrayParam()

使用数组形式[key=>value]设置参数。
它还标记参数为缺失=false

参数

  • $array 要用于设置参数的关联数组。(数组)
  • $excludeKeys 您可以添加要排除的键。
    如果键在数组中且在此列表中,则将其排除(数组)
  • $includeKeys 仅可包含元素的白名单
    仅添加在此列表中的键。(数组或null)

方法 reconstructPath()

用于内部重建当前脚本的路径。

参数

  • $includePHP 参数 bool $includePHP(布尔值)
  • $trimArguments 参数 int $trimArguments(整数)

方法 getPhpOriginalFile()

获取PHP原始文件

方法 setPhpOriginalFile()

设置PHP原始文件

参数

  • $phpOriginalFile 参数字符串 $phpOriginalFile (字符串)

方法 setColor()

在堆栈中设置颜色

参数

  • $colors =['red','yellow','green','white','blue','black',cyan','magenta'][$i] (数组)

方法 setParam()

手动设置参数的值或值键。
同时标记参数的来源为"已设置"并将参数标记为不存在=false

参数

  • $key 参数的键(字符串)
  • $value 要分配的值(或值键)。(混合类型)
  • $isValueKey 如果 false(默认)则参数 $value 是参数的值
    如果 true 则参数 $value 是值键。 (布尔型)
  • $createIfNotExist 如果为 true 且参数不存在,则使用默认配置创建。 (布尔型)

方法 setParamUsingArray()

使用数组设置参数的值。
如果参数不存在,则使用默认值创建

参数

  • $assocArray 形式为 ['key'=>'value'] 的关联数组 (数组|null)
  • $fields 如果为 null,则设置数组的所有值
    如果不为 null,则用于确定哪些字段将被使用(数组|null)

方法 createContainer()

使用未来。它创建一个容器。

参数

  • $width 参数 $width ()
  • $height 参数 $height ()

方法 getValueAsArray()

获取参数值的关联数组。

参数

  • $fields 如果字段为 null,则返回所有参数,包括 "none"。 (数组|null)
  • $asAssocArray (默认 true) 如果为 true,则将值作为关联数组返回
    如果为 false,则作为索引数组返回。 (布尔型)

方法 setPatternTitle()

设置标题使用的模式。此操作在堆栈中使用。 {value} {type}

参数

  • $pattern1Stack 如果为 null,则使用默认值。 (?字符串)

方法 setPatternCurrent()

{value}{type}

参数

  • $pattern2Stack 如果为 null,则使用默认值。 (?字符串)

方法 setPatternSeparator()

">"

参数

  • $pattern3Stack 如果为 null,则使用默认值。 (?字符串)

方法 setPatternContent()

尚未使用。

参数

  • $pattern4Stack 如果为 null,则使用默认值。 (?字符串)

方法 setStyle()

设置不同元素使用的样式

参数

  • $style =['mysql','simple','double','minimal','style'][$i] (字符串)
  • $waitingIconStyle =['triangle','braille','pipe','braille2','bar','bar2','bar3','arc','waiting'][$i]
    如果是数组,则使用数组的元素来显示等待图标(字符串|数组)

方法 show()

与 showLine 类似,但保持在当前行。

参数

  • $content 参数字符串 $content (字符串)
  • $stream =['stdout','stderr','memory'][$i] (?字符串)

方法 showBread()

显示导航路径。
要添加值,可以使用 uplevel() 方法
要删除一个值(向下一个层级),可以使用 downlevel() 方法
也可以通过 setPattern1()、setPattern2()、setPattern3() 改变样式

$cli->setPattern1('{value}{type}') // the level
->setPattern2('<bred>{value}</bred>{type}') // the current level
->setPattern3(' -> ') // the separator
->showBread();

显示当前导航路径(如果有的话)。

参数

  • $showIfEmpty 如果为 true,则即使为空(空行)也会显示导航路径
    如果为 false(默认),则如果为空时不显示导航路径。 (布尔型)

方法 showCheck()

在单行中显示标签消息,例如:[ERROR] 错误消息

参数

  • $label 参数字符串|数组 $label (字符串|数组)
  • $color =['red','yellow','green','white','blue','black',cyan','magenta'][$i] (字符串)
  • $content 参数字符串|数组 $content (字符串|数组)
  • $stream =['stdout','stderr','memory'][$i] (字符串)

方法 showFrame()

显示边框框架。

参数

  • $lines 内容。 (字符串|字符串数组)
  • $titles 如果为 null,则没有标题。 (字符串|字符串数组|null)

方法 showLine()

显示(echo)带有颜色的行。颜色的语法类似于 html,如下所示
示例

<red>error</red>; (color red)
<yellow>warning</yellow> (color yellow)
<blue>information</blue> (blue)
<yellow>yellow</yellow> (yellow)
<green>green</green>  (color green)
<italic>italic</italic>
<bold>bold</bold>
<bred>error</bred>; (color background red, it also works for the other colors <b*>)
<dim>dim</dim>
<invisible>invisible</invisible> (it could not work in some terminals)
<underline>underline</underline>
<strikethrough>strikethrough</strikethrough>
<cyan>cyan</cyan> (color light cyan)
<magenta>magenta</magenta> (color magenta)
<col0/><col1/><col2/><col3/><col4/><col5/>  columns. col0=0
(left),col1--col5 every column of the page.
<option/> it shows all the options available (if the input has some options)

参数

  • $content 要显示的内容 (字符串|字符串数组)
  • $cliOneParam 参数 ?CliOneParam $cliOneParam (?CliOneParam)
  • $stream =['stdout','stderr','memory'][$i] (?字符串)

方法 clearScreen()

清除当前屏幕
示例

$this->clearScreen(); // clear the screen
$this->clearScreen()->cursorHome(); // clear the screen and put the cursor at the home position

方法 cursorHome()

将光标设置为左上角位置
示例

$this->cursorHome(); // put the cursor at the home position

方法 cursorMove()

将光标移动到某个特定位置
示例

$this->cursorMove('up',5); // move relatively 5 up
$this->cursorMove('upmost',1); // move to the up position down 1.
$this->cursorMove('down',5); // move relatively 5 down
$this->cursorMove('downmost',2); // move to the down position up 2
$this->cursorMove('right',10); // move relatively 5 right
$this->cursorMove('rightmost',5); // move to the rightmost position, minus 5
$this->cursorMove('left',10); // move relatively 5 left
$this->cursorMove('leftmost',5); // move to the leftmost position, minus 5
$this->cursorMove('pos',[10,10]); // move absolute to the position 10,10

参数

  • $type=['up','upmost','down','downmost','right','rightmost','left','leftmost','pos'][$i]
  • up : 移动光标向上 "n" 参数
  • down : 移动光标向下 "n" 参数
  • right : 移动光标向右 "n" 参数
  • left : 移动光标向左 "n" 参数
  • upmost : 将光标移动到上方减去 "n" 处
  • downmost : 将光标移动到下方减去 "n" 处
  • rightmost : 将光标移动到最右方减去 "n" 处
  • leftmost : 将光标移动到最左方减去 "n" 处
  • pos : 将光标移动到 [x,y] 参数
    (字符串)
  • $parameter 参数混合 $parameter (混合)

方法 bell()

方法 getCursorPosition()

获取光标当前位置

需要配置 Windows 中的 getCh() 可执行文件并启动 示例:

$arr=$this->getCursorPosition(); // [x,y]

方法 showMessageBox()

显示包含两列的消息框。

参数

  • $lines (右侧) (字符串|string[])
  • $titles (左侧) (字符串|string[])
  • $wrapLines 如果为 true,则 $lines 可以为换行(如果行太长)(布尔值)

方法 alignLinesVertically()

参数

  • $lines 要对齐的行 (字符串[])
  • $numberLines 用于对齐文本的垂直行数。 (整数)
  • $align =['middle','top','bottom'][$i] (字符串)

方法 maxWidth()

方法 showParamSyntax()

显示参数的语法。

参数

  • $key 要显示的键。 "*" 表示所有键。 (字符串)
  • $tab 第一分隔符。值介于 0 和 5 之间。 (整数)
  • $tab2 第二分隔符。值介于 0 和 5 之间。 (整数)
  • $excludeKey 要排除的键。它必须是一个索引数组,包含要跳过的键。 (数组)

方法 showParamSyntax2()

显示参数的语法。

参数

  • $title 标题(可选)(?字符串)
  • $typeParam =['command','first','last','second','flag','longflag','onlyinput','none'][$i] 参数类型 (数组)
  • $excludeKey 要排除的键 (数组)
  • $includeKeys 仅可包含元素的白名单
    仅添加在此列表中的键。(数组或null)
  • $related 如果不为空,则只显示所有相关的参数。
    使用 $param->setRelated() 来设置关系。 (字符串|null)
  • $size 第一列的最小大小 (?整数)

方法 setDefaultStream()

参数

  • $stream =['stdout','stderr','memory'][$i] (字符串)

方法 setNoColor()

参数

  • $noColor 如果 true,则不会显示颜色
    如果 false,则显示颜色。 (布尔值)

方法 isNoColor()

方法 setNoANSI()

如果为 true,则控制台处于 old-cmd 模式(无颜色,无 utf-8 字符等)

参数

  • $noANSI 参数布尔值 $noANSI (布尔值)

方法 isNoANSI()

如果返回 true

方法 wrapLine()

它包装一行并返回一行或多行
包装的行不会打开或关闭标签。

参数

  • $texts 已格式化的文本。 (字符串|array)
  • $width 预期宽度 (整数)
  • $keepStyle 如果为 true,则保留每行的初始和结束样式标签。
    如果为 false,则仅包装行。 (布尔值)

方法 showProgressBar()

参数

  • $currentValue 当前值 (数字)
  • $max 填充条的最大值。 (数字)
  • $columnWidth 条的大小(以列为单位)(整数)
  • $currentValueText 要在左侧显示的当前值。
    如果为 null,则显示当前值(用空格分隔)(?字符串)

方法 getPageSize()

获取要显示在表格中的页面大小(行数)

方法 showTable()

显示关联数组。此命令是堆栈的结束。

参数

  • $assocArray 要显示值的关联数组。键用作索引。 (数组)
  • $notop 如果为 true,则不会显示顶部边框 (布尔值)
  • $nosides 如果为 true,则不会显示侧面边框 (布尔值)
  • $nobottom 如果为 true,则不会显示底部边框 (布尔值)
  • $maxColumns 要显示的最大列数。
    如果表格有15列且maxColumns为5,则只显示前5列。(整型)
  • $reduceRows 考虑屏幕大小要减少的行数。
    如果屏幕有30行,则表格将使用30-3=27行
    如果设置为 >-99999,则将显示所有行。(整型)
  • $curpage 要显示的页数(基准为1)。(整型)

方法 showValuesColumn()

以列的形式显示值。

参数

  • $values 要显示的值。它可以是一个关联数组或索引数组。(数组)
  • $type ['multiple','multiple2','multiple3','multiple4','option','option2','option3','option4'][$i] (字符串)
  • $patternColumn 要使用的模式,例如:“[{key}] {value}”(字符串)

方法 showWaitCursor()

显示等待光标。
示例

$this->hideCursor()->showWaitCursor(true);
$this->showWaitCursor(); // inside a loop.
$this->hideWaitCursor()->showCursor(); // at the end of the loop

参数

  • $init 在第一次调用此方法时,您必须将此值设置为true。然后,每次更新都必须为false。(布尔型)
  • $postfixValue 如果您想设置前缀值,如百分比、提前等。(字符串)

方法 hideWaitCursor()

方法 hideCursor()

方法 showCursor()

方法 showparams()

通过显示键、默认值和值来显示所有参数
用于调试和测试。

方法 showParamValue()

参数

  • $parameter 参数 CliOneParam $parameter(CliOneParam)

方法 strlen()

确定字符串的大小

参数

  • $content 参数 $content ()
  • $visual visual表示考虑视觉长度,false表示考虑字符。(布尔型)

方法 removechar()

移除字符串末尾的可见字符。它忽略了不可见字符(如颜色)。

参数

  • $content 参数字符串 $content (字符串)
  • $numchar 参数 int $numchar (整型)

方法 upLevel()

在面包屑中向上提升一级

参数

  • $content 新行的内容(字符串)
  • $type 内容的类型(可选)(字符串)

方法 getCh()

它读取输入字符。它不与特殊字符一起工作
此功能是基本的,它不适用于所有按键,并且可能很费CPU(对于循环)

在Windows中,它使用任何路径文件夹中的getch.exe(或者您可以设置路径为 $this->getChWinExe)。
您可以在此处下载:https://github.com/escuelainformatica/getch/releases 示例:

$chNumber=$this->getCh(); // wait until it reads a character
while(true) {
$chNumber=$this->getCh(false); // does not wait.
usleep(50); // if you don't add a pause, it uses the CPU 100%
}
$chChar=$this->getCh(false,false); // it gets a character instead of a number

参数

  • $waitUntilKeyPress 如果为true(默认),它将等待按键按下(布尔型)
  • $asNumber 如果为true(默认),则将结果作为双字节整数返回(布尔型)

方法 colorText()

它设置cli的颜色

<red>error</red> (color red)
<yellow>warning</yellow> (color yellow)
<blue>information</blue> (blue)
<yellow>yellow</yellow> (yellow)
<green>green</green>  (color green)
<italic>italic</italic>
<bold>bold</bold>
<underline>underline</underline>
<strikethrough>strikethrough</strikethrough>
<cyan>cyan</cyan> (color light cyan)
<magenta>magenta</magenta> (color magenta)
<col0/><col1/><col2/><col3/><col4/><col5/>  columns. col0=0 (left),col1--col5 every column of the page.
<option/> it shows all the options available (if the input has some options)

参数

  • $content 参数字符串 $content (字符串)
  • $cliOneParam 参数 ?CliOneParam $cliOneParam (?CliOneParam)

方法 colorLess()

它删除内容中的所有转义字符

参数

  • $content 参数字符串 $content (字符串)

方法 colorMask()

它使用字符250掩码所有转义字符

参数

  • $content 参数 $content ()

方法 initialEndStyle()

它返回文本的初始和结束样式
如果文本只包含初始或结束样式,则不返回任何内容

参数

  • $contentAnsi 已格式化为Ansi的文本内容(字符串)
  • $initial (此值返回) (?字符串)
  • $end (此值返回) (?字符串)

方法 replaceCurlyVariable()

用值字典中的变量替换{{ }}之间的所有变量
示例

replaceCurlyVariable('hello={{var}}',['var'=>'world']) // hello=world
replaceCurlyVariable('hello={{var}}',['varx'=>'world']) // hello=
replaceCurlyVariable('hello={{var}}',['varx'=>'world'],true) // hello={{var}}

参数

  • $string 输入值。它可以包含定义为{{namevar}}的变量(字符串)
  • $notFoundThenKeep [false] 如果为true且值未找到,则保留值。否则,它被替换为空值(布尔型)

菜单

您可以使用以下方法创建菜单

添加菜单()

创建新的菜单

添加菜单项()

向菜单添加选项

添加多个菜单项()

向菜单添加多个选项

评估菜单()

执行菜单

清除菜单()

清除菜单。

示例

class ClassService {
  public function menuHeader(CliOne $cli) { /* todo: add header code */ }
  public function menuFooter(CliOne $cli) { /* todo: add footer code */ }
  public function menuOption1(CliOne $cli) { /* todo: add menu option 1 code */ }
  public function menuOption2(CliOne $cli) { /* todo: add menu option 2 code */ }
}
$obj=new ClassService();

$cli = new CliOne();
$cli->addMenu('menu1', 'header','footer');
$cli->addMenuItem('menu1','option1', 'option #1'
  ,function($cli) {$cli->showLine('calling action1');$this->assertTrue(true, true);});
$cli->addMenuItem('menu1','option2', 'option #2');
$cli->addMenuItem('menu1','option3', 'option #3','navigate:menu1.1');
$cli->addMenuItems('menu1',['option4'=>'option #4','option5'=> 'option #5']); // adding multiples options

$cli->addMenu('menu1.1', 'header2','footer2');
$cli->addMenuItem('menu1.1','option1', 'option #1.1');
$cli->addMenuItem('menu1.1','option2', 'option #2.1');
$cli->addMenuItem('menu1.1','option3', 'option #3.1');
$cli->addMenuItem('menu1.1','option4', 'option #4.1');
$cli->addMenuItem('menu1.1','option5', 'option #5.1');
$cli->evalMenu('menu1',$obj); // runs the menu.
$cli->showLine('exit ok');
$cli->clearMenu();

示例

使用参数的示例

示例/example1.php

并创建以下代码

// example1.php
// don't forget to add autoloader, namespace, etc.
$cli=new CliOne(); // instance of the library
if($cli->isCli()) { // we validate if we are running a CLI or not.
  $cli->createParam('param1') // the name of the parameter
        ->setDescription('Some description','question?') // description and question
        ->setRequired(true) // if the field is required
        ->setDefault('param1') // the default value If the value is not found
        ->add(); // it adds a parameter to the cli
  $param1=$cli->evalParam('param1'); // then we evaluate the parameter.
  var_dump($param1->value);  
}

因此,您可以像这样运行

使用用户输入的示例

您可以请求用户输入。

示例/example2.php

$cli=new CliOne();
if($cli->isCli()) {
    $cli->createParam('param1')
        ->setDescription('This field is called param1 and it is required')
        ->setInput(true,'string')
        ->setRequired(true)
        ->setDefault('param1')
        ->add();
    $param1 = $cli->evalParam('param1');
    var_dump($param1->value);
}

将显示以下结果

游戏示例

示例/examplegame.php

docs/guess.jpg 图像(c)George Beker

docs/examplegame.jpg

颜色示例

您可以在颜色类型中看到可用的标签。

example/examplecolor.php

$cli->showLine("<bold>bold</bold>");
$cli->showLine("<dim>dim</dim>");
$cli->showLine("<bred>background red</bred>");
$cli->showLine("<bblue>background red</bblue>");
$cli->showLine("<bwhite><black>background white</black> </bwhite>");
$cli->showLine("<byellow><blue>background yellow</blue></byellow>");
$cli->showLine("<red>error</red> (color red)");
$cli->showLine("<yellow>warning</yellow> (color yellow)");
$cli->showLine("<blue>information</blue> (blue)");
$cli->showLine("<yellow>yellow</yellow> (yellow)");
$cli->showLine("<green>green</green> (color green)");
$cli->showLine("<italic>italic</italic>");
$cli->showLine("<bold>bold</bold>");
$cli->showLine("<bold><yellow>bold yellow</yellow></bold>");
$cli->showLine("<strikethrough>stike</strikethrough>");
$cli->showLine("<underline>underline</underline>");
$cli->showLine("<cyan>cyan</cyan> (color cyan)");
$cli->showLine("<magenta>magenta</magenta> (color magenta)");
$cli->showLine("<bold><cyan>bold cyan</cyan></bold> (color cyan)");
$cli->showLine("<bold><magenta>bold magenta</magenta></bold> (color magenta)");
$cli->showLine("<bblue><col0/> col0</bblue>");
$cli->showLine("<bblue><col1/> col1</bblue>");
$cli->showLine("<bblue><col2/> col2</bblue>");
$cli->showLine("<bblue><col3/> col3</bblue>");
$cli->showLine("<bblue><col4/> col4</bblue>");
$cli->showLine("<bblue><col1/> col1 <col3/> col3 <col5/> col5</bblue>");
$cli->showLine("The parameters of option are: <option/>",$cli->getParameter('test'));

表格示例

example/exampletables.php

docs/exampletable.jpg

用户输入类型

颜色类型

定义

您可以在

definitions.md

调试

要启用调试模式,必须将debug字段设置为true

$cli=new CliOne();
$cli->debug=true;

在调试模式下,每个用户输入都会记录在字段$debugHistory中

您也可以运行输入??history查看历史记录

您还可以使用输入??clear清除历史记录

目标是我们可以存储会话并使用testUserInput()替换它

您还可以加载和保存用户输入

  • ??history 显示历史记录
  • ??clear 清除历史记录
  • ??load 加载用户输入并运行它。
  • ??save 将用户输入保存到名为_save.json的文件中
  • ??load:file ??save:file 您也可以指定要保存的文件名
$cli = new CliOne();
CliOne::testUserInput([...]); // put your story here.

兼容性

  • 它必须支持所有与虚拟终端兼容的现代接口。
  • 自Windows TH2 (v1511, 2015)以来,cmd.exe和powershell.exe已支持VT,但必须启用。
    • REG ADD HKCU\CONSOLE /f /v VirtualTerminalLevel /t REG_DWORD /d 1
  • 自Windows 10周年版 (v1607, 2016)以来,cmd.exe和powershell.exe默认支持VT(据我所知)
  • Windows 2019 (LTS, 2018)默认支持此库。
  • Windows Terminal支持所有功能。
  • 在较旧版本的Windows中,屏幕宽度比列少一列。微软,加油!

变更日志

  • 1.35 (2024-09-23)

    • new 方法 clearScreen()
    • new 方法 cursorHome()
    • new 方法 cursorMove()
    • new 方法 bell()
    • new 方法 getCursorPosition()
    • fixed 修复了一些注释。
  • 1.34 (2024-09-20)

    • 修复了showTable()中的几个错误。
    • 修复了代码中的注释
  • 1.33 (2024-08-02)

    • json_encode不再抛出异常。现在它会在空值或默认值时失败。
  • 1.32.1 (2024-03-02)

    • 修复了一些字段、默认值和类型提示。
  • 1.32 (2024-03-02)

    • 更新依赖项到PHP 7.4。PHP 7.2的扩展支持已于3年前结束。
    • 在代码中添加了更多的类型提示。
  • 1.31 (23-09-02)

    • 新方法
      • hideCursor()
      • showCursor()
    • 修改方法
      • setStyle()现在允许两个参数。
  • 1.30 (23-09-02)

    • 最佳Windows版本识别。10.1607及以上版本被认为是兼容的。
    • 修复:滚动和等待光标现在可以正确工作。
    • 初步容器。
  • 1.29.1 (23-04-06)

    • 修复了addMenuService()的错误。
  • 1.29 (23-04-06)

    • 在调试模式下,您可以执行??load、??save操作。
  • 1.28 (2023-04-05)

    • 的$debug字段,因此您可以调试并存储用户输入历史。
    • PHP_FAKE_READLINE常量或全局变量现在是静态字段$fakeReadLine
  • 1.27 (2023-04-02)

    • 新方法instance(),这样您就可以获取或创建一个新的单例实例。
    • 新方法hasInstance()
    • 新方法hasMenu()
    • 新方法addMenuService()
    • 修复了showHelp()和帮助是数组或帮助缺失的错误。
  • 1.26.1 (2023-03-21)

    • 清理了一些代码。
  • 1.26 (2023-03-21)

    • addMenu()和addMenuItem()允许使用可调用参数。
  • 1.25.1 (2023-03-20)

    • 修复了evalMenu()的微小错误。
    • 添加了addMenu()($size)选项
  • 1.25 (2023-03-20)

    • 添加了clearMenu()、addMenu()、addMenuItem()、addMenuItems()、evalMenu()方法
    • 添加了setVariable()、getVariable()和addVariableCallBack()方法。$variable字段现在是私有的。
  • 1.24 (2023-03-11)

    • 添加了新方法createOrReplaceParam()、setParamUsingArray()、getValueAsArray()
    • setParam()新增参数,用于在未定义时创建参数。
    • 添加了可以在文本包含"{{namevar}}"时显示的变量
  • 1.23 (2023-03-05)

    • 添加了新方法readDataPHPFormat()和saveDataPHPFormat()
    • readDate()和saveData()生成一个包含版本和生成日期的文件。它不会影响旧文件。
  • 1.22.3 (2023-03-04)

    • 修复了某些值为null时的小错误。它可能会在PHP中引发警告
  • 1.22.2 (2023-02-17)

    • 一些清理
  • 1.22.1 (2022-7-30)

    • 修复代码中的一个小错别字。
  • 1.22 (2022-07-30)

    • setInput()添加了宽格式,用于1列(如果屏幕宽度等于或小于80列)或两列
    • "选项"忽略大小写。
  • 1.21 (2022-06-27)

    • showMessageBox() 现在支持颜色和换行。
  • 1.20 (2022-06-21)

    • showMessageBox() 添加了换行功能。
    • 更新了判断数组是否关联的方法。
  • 1.19 (2022-06-18)

    • 更新了创建表格的方式。
  • 1.18.1 (2022-06-17)

    • 修复了当使用 setCurrentAsDefault() 但值类型为选项时(我们设置了默认的 valuekey 而不是 value)的bug。
  • 1.18 (2022-06-11)

    • 添加了 addExtensionFile() 方法。
  • 1.17 (2022-06-09)

    • 修复了与 Linux 相关的许多问题(行数、自动完成等)。
  • 1.16 (2022-03-25)

    • setParam() 允许设置值或值键。
  • 1.15 (2022-03-15)

    • showHelp() 显示更多信息。
    • colorText() 现在正确处理了一些缺失的标签。
  • 1.14 (2022-03-04)

    • showTable() 方法允许显示或隐藏顶部、侧面和底部边框。
  • 1.13 (2022-02-28)

    • 将 silentError 更改为 errorType。
  • 1.12 (2022-02-26)

    • CliOne
      • 添加了内存流。
      • 设置默认流。
      • 将当前流设置为使用 stdout、stderr 或内存(stdin 不用于 in)。
      • 添加了一个新的参数类型 "command",它等于第一个参数,但忽略名称并考虑位置。
      • 添加了 showHelp() 方法。
      • 添加了 makeBigWords() 方法。
      • 添加了 fontZnaki()。
      • 添加了 fontaatr()。
        • 这两个字体在代码中占用大量空间,但它们只是位数组,因此它们只占用 2KB。
      • 新方法 alignLinesVertically()。
      • 新方法 maxWidth()。
      • 将字段 cmdMode 重命名为 noANSI。
      • method initialEndStyle()。
    • CliOneParam。
      • 添加了一个相关字段。
  • 1.11 (2022-02-22)

    • 添加了对 STDIN、STDOUT 和 STDERR 的支持。
  • 1.10 (2022-02-21)

    • [新功能] 对旧命令行(cmd.exe)的支持。它将自动激活。
      • 它将颜色降级为黑白,并将 utf-8 字符转换为兼容。
      • 此外,在此模式下不会显示滚动条和等待光标。
      • 有关更多信息,请参阅兼容性。
  • 1.9 (2022-02-20)

    • [新功能] argumentIsValueKey 和内存。
    • [变更] 更改了 createParam() 的签名,交换了第二个和第三个参数
  • 1.8 (2022-02-20)

    • [新功能] setParam() 如果参数未定义,则抛出异常。
    • [新功能] showParamSyntax2()。
    • [新功能] CliOneParam::$nameArg 参数名称(用于帮助)。
  • 1.7 (2022-02-18)

    • [修复] 为大多数字段和方法添加了类型提示。
    • [新功能] 为 CliOneParam 添加了新的 setValue()。
  • 1.6.1 (2022-02-18)

    • [修复] 修复了手动设置值时的小 bug,因此它仍然被标记为缺失。
  • 1.6 (2022-02-18)

    • [新功能] new method isParameterPresent()。
  • 1.5.5 (2022-02-18)

    • getParameter() 总是返回一个参数,无论它是否存在。
      • 您可以使用 isValid() 方法来检查其有效性。
    • setSilentError() 可以静默错误输出。
    • addhistory() 重命名为 setAddHistory()。
    • 添加新参数时,add() 会验证键是否已被使用,键是否是其他键的别名,或者别名是否已被使用。
  • 1.5.4 (2022-02-18)

    • 修复了默认值的问题。
    • 添加了历史记录(如果可用)。
  • 1.5.3 (2022-02-18)

    • 没有,只是重新编号。
  • 1.5.2 (2022-02-18)

    • [修复] 代码的一些清理。
  • 1.5.1 (2022-02-18)

    • [修复] 当类型为 "none" 时,修复了返回 null 而不是 false 的问题。
    • [新功能] CliOneParam::evalParam() 可以返回值而不是实例。
  • 1.5 (2022-02-17)

    • [修复] 修复了文本使用颜色时显示和截断的问题。
    • [新功能] 它允许多种类型的参数(不仅仅是标志),包括位置参数、标志、长标志和 none。
    • [新功能] 添加了堆栈。一些视觉元素允许堆叠值。
  • 1.4.1 (2022-02-15)

    • [修复] 对 unicode 字符的一些修复。如果库可用,系统将自动使用 MB_STRING。否则,它将使用默认库。
    • [新功能] 为组件添加了新的样式和模式。
  • 1.4 (2022-02-15)

    • [替换] 现在所有颜色都表示为非缩写 "" => "", 等。
    • [新功能] 添加了所有基本颜色、背景并解决了下划线的问题。
    • [新功能] 添加了 showFrame()、showTable()、showWaitCursor()、showProgressBar()
  • 1.3 (2022-02-14)

    • [新功能] 添加了自动完成功能(Tab键)
    • [新功能] 添加了面包屑导航
    • [新功能] 添加了 showValuesColumn()
    • [替换] 现在的键(在选项中显示)居中对齐。
  • 1.2.2 (2022-02-14)

    • [修复] 修复了问题:问题被省略号(...)截断
  • 1.2.1 (2022-02-13)

    • [修复] 修复了一些错误
    • [新功能] 键填充,例如 /[ 1] /[ 2] /[ 3] ... [99],/[value 1] /[value 2] /[value ]
  • 1.2 (2022-02-13)

    • [替换] “options”更名为“multiple”。添加了“multiple2”、“multiple3”、“multiple4”
    • [新功能] 允许关联数组。
    • [新功能] 添加了模板。
    • [新功能] 添加了 valuekey。
  • 1.1 (2022-02-12)

    • [新功能] 新增了 savedata()、getArrayParams()、setArrayParam()、readData() 方法
    • [替换] 为 replaceColor() 方法添加了一个新参数
    • [新功能] 新增了一种类型:密码
  • 1.0.1 (2022-02-11)

    • [修复] 命名空间
    • [修复] replaceColor() 修复了颜色问题
    • [新增] CliOne::indVendorPath()
  • 1.0 (2022-02-11)

    • 结束测试阶段,首次发布。
  • 0.7 (2022-02-11)

    • 添加了 option4。
    • optionshorts 允许指定第一个字母,只有当第一个字母唯一时才有效,例如:yes/no 允许使用 y/n
  • 0.6 (2022-02-11)

    • 添加了 option2 和 option3
    • allowNulls() 现在不与默认值一起使用。
  • 0.5 (2022-02-03)

    • [单元测试] 更好的单元测试。
    • [CliOneParam] 您可以设置是否允许空值。
    • [CliOne] 您可以设置是否允许空值。
  • 0.4 (2022-01-27) 现在测试覆盖率超过 75%

  • 0.3 (2022-01-26) 对读取值的修正

  • 0.2 一些更新

  • 0.1 首个版本