eftec / clione
适用于Windows和Linux的PHP命令行(CLI)生成器
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-23 12:22:30 UTC
README
这个库帮助在Windows、Mac和Linux上创建PHP的命令行(CLI)操作员
功能
✅ 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
我们有两个参数,第一个(读取)位于第一个位置,它没有任何"-"。第二个是"-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
还有更多操作可用,但基本操作都在那里。
目录
- CliOne
- 目录
- 流程
- 作为参数输入
- 交互式输入
- CliOne类
- 方法 __construct()
- 方法 getWindowsVersion()
- 方法 instance()
- 方法 hasInstance()
- 方法 hasMenu()
- 方法 clearMenu()
- 方法 addMenu()
- 方法 addMenuItem()
- 方法 addMenuItems()
- 方法 addMenuService()
- 方法 evalMenu()
- 方法 getErrorType()
- 方法 getMemory()
- 方法 setVariable()
- 方法 getVariable()
- 方法 addVariableCallBack()
- 方法 callVariablesCallBack()
- 方法 hasColorSupport()
- 方法 testArguments()
- 方法 testUserInput()
- 方法 setMemory()
- 方法 setErrorType()
- 方法 findVendorPath()
- 方法 createParam()
- 方法 createOrReplaceParam()
- 方法 downLevel()
- 方法 evalParam()
- 方法 throwError()
- 方法 showWarning()
- 方法 addHistory()
- 方法 setHistory()
- 方法 clearHistory()
- 方法 listHistory()
- 方法 getArrayParams()
- 方法 getColSize()
- 方法 getParameter()
- 方法 getValue()
- 方法 readArgument()
- 方法 showHelp()
- 方法 makeBigWords()
- 方法 getValueKey()
- 方法 isCli()
- 方法 getSTDIN()
- 方法 readData()
- 方法 readDataPHPFormat()
- 方法 isParameterPresent()
- 方法 addExtensionFile()
- 方法 saveData()
- 方法 saveDataPHPFormat()
- 方法 setAlign()
- 方法 setArrayParam()
- 方法 reconstructPath()
- 方法 getPhpOriginalFile()
- 方法 setPhpOriginalFile()
- 方法 setColor()
- 方法 setParam()
- 方法 setParamUsingArray()
- 方法 createContainer()
- 方法 getValueAsArray()
- 方法 setPatternTitle()
- 方法 setPatternCurrent()
- 方法 setPatternSeparator()
- 方法 setPatternContent()
- 方法 setStyle()
- 方法 show()
- 方法 showBread()
- 方法 showCheck()
- 方法 showFrame()
- 方法 showLine()
- 方法 clearScreen()
- 方法 cursorHome()
- 方法 cursorMove()
- 方法 bell()
- 方法 getCursorPosition()
- 方法 showMessageBox()
- 方法 alignLinesVertically()
- 方法 maxWidth()
- 方法 showParamSyntax()
- 方法 showParamSyntax2()
- 方法 setDefaultStream()
- 方法 setNoColor()
- 方法 isNoColor()
- 方法 setNoANSI()
- 方法 isNoANSI()
- 方法 wrapLine()
- 方法 showProgressBar()
- 方法 getPageSize()
- 方法 showTable()
- 方法 showValuesColumn()
- 方法 showWaitCursor()
- 方法 hideWaitCursor()
- 方法 hideCursor()
- 方法 showCursor()
- 方法 showparams()
- 方法 showParamValue()
- 方法 strlen()
- 方法 removechar()
- 方法 upLevel()
- 方法 getCh()
- 方法 colorText()
- 方法 colorLess()
- 方法 colorMask()
- 方法 initialEndStyle()
- 方法 replaceCurlyVariable()
- 菜单
- 示例
- 用户输入类型
- 颜色类型
- 定义
- 调试
- 兼容性
- 变更日志
流程
- (可选)您可以使用 setParam() 方法设置当前值
- 如果参数类型不是 "onlyinput" 和 "none",则读取参数
- 示例:php program.php -param1 value --param2 -param3="hello world" 位置参数
- 如果找到参数,则返回它,结束流程。
- 如果没有找到参数,那么
- 如果 setCurrentAsDefault() 被设置,并且当前值不为 null,则默认值是当前值。
- 否则,默认值是使用 setDefault() 方法设置的值。如果没有设置,则使用 null。
- 如果输入为 true,则 setInput(true),然后它会要求用户输入值
- 如果用户没有填写信息,则返回默认值(如果有的话),结束流程
- 如果用户填写了信息,但信息不正确,则会反复询问。
- 如果用户填写了正确的信息,则返回此值,结束流程
- 如果输入为 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可选,每次菜单显示时调用的方法名称
必须具有前缀menu的方法被调用:“opt1”,method:“menuopt1”。如果$headFunction是可调用的,则调用该函数。(字符串或null或可调用的) - $footerFunction 可选,每次菜单结束显示时调用的方法名称。被调用的方法必须以“menu”为前缀。
如果 $footerFunction 可调用,则调用该函数(string|null|callable) - $question 输入问题。 (string)
- $size =['option','option2','option3','option4','wide-option','wide-option2'][$i] 选项菜单的大小。(string)
方法 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 菜单的唯一索引。用于选择和操作(如果没有提供操作)。 (string)
- $description 菜单的描述(string)
- $action 动作是调用的方法(方法必须以“menu”为前缀)。
如果动作以 "navigate:" 开头,则打开指示的菜单。
如果动作是 "exit:",则退出菜单。
如果动作是可调用的,则调用该函数(string|null|callable)
方法 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]
(array|null)
方法 addMenuService()
在运行 evalMenu() 时评估要添加的服务对象。
您可以添加菜单服务。每个服务按顺序评估,因此如果两个服务对象具有相同的方法,则仅由第一个对象调用。
如果 evalMenu() 使用服务,则忽略这里定义的服务。
示例
$objService=new Class1();
$this->addMenuService('menu1',$objService);
// or:
$this->addMenuService('menu1',Class1:class);
参数
- $idMenu菜单的唯一名称(字符串)
- $service 服务对象或类的名称。
如果是类的名称,则创建其实例。(object|string)
方法 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()(object|null|array)
方法 getErrorType()
方法 getMemory()
方法 setVariable()
将值设置到数组中。
参数
- $variableName 变量的名称。如果变量存在,则将其替换。(string)
- $value 分配的值。(mixed)
- $callBack 如果值为 true(默认),则每次修改(如果值已更改)将调用在 addVariableCallBack() 中定义的函数。
如果为 false,则不调用回调函数。(bool)
方法 getVariable()
获取变量的值
参数
- $variableName 变量的名称(string)
- $valueIfNotFound 如果未找到,则返回此值(mixed|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 函数的名称。如果函数存在,则将其替换。(string)
- $function 如果函数为 null,则删除分配的函数。
函数可以使用类型为 CliOne 的参数定义。(callable|null)
方法 callVariablesCallBack()
调用回调函数。通常它们在每次调用 setVariable()(并且值已更改)时调用。
方法 hasColorSupport()
此函数基于 Symfony。
方法 testArguments()
用于测试。您可以使用此函数模拟参数。
此函数必须在创建实例之前调用。
参数
- $arguments 参数数组 $arguments (array)
方法 testUserInput()
用于测试。您可以使用此函数模拟用户输入。
此函数必须在每次交互之前调用。
此函数不会自动重置,要重置,请设置 $userInput=null。
参数
- $userInput 参数 ?array $userInput (?array)
- $throwNoInput(默认:true)如果为 true,则在没有输入时抛出异常
如果为 false,则如果没有更多输入,则清除 userInput(bool)
方法 setMemory()
设置存储到内存流中的值。
如果内存流有值,则删除并替换它们。
参数
- $memory 要存储的值(string)
方法 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 如果为 true,则返回获取的值。
如果为 false(默认值),则返回 CliOneParam 的实例。
方法 throwError()
它引发一个错误。根据类型,它可能显示错误或抛出运行时异常。
参数
- $msg 参数字符串 $msg(字符串)
方法 showWarning()
显示警告
参数
- $msg 参数数组|string $msg(数组|string)
方法 addHistory()
将值添加到历史记录中
参数
- $prompt 要添加的历史记录的值(字符串|数组)
方法 setHistory()
使用新值设置历史记录(删除旧历史记录)
参数
- $prompt 参数字符串|数组 $prompt(字符串|数组)
方法 clearHistory()
清除全局历史记录(如果有的话)。
方法 listHistory()
检索全局历史记录(如果有的话)
方法 getArrayParams()
返回一个包含所有参数的关联数组 [键=>值]
忽略类型为 "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 参数布尔值 $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()
Util类。如果文件名没有扩展名,则仅向文件名添加默认扩展名。
参数
- $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 参数布尔值 $includePHP (布尔值)
- $trimArguments 参数整型 $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 如果为真且参数不存在,则使用默认配置创建它。 (布尔值)
方法 setParamUsingArray()
使用数组设置参数的值。
如果参数不存在,则使用默认值创建它。
参数
- $assocArray 形如 ['key'=>'value'] 的关联数组 (数组|null)
- $fields 如果为 null,则设置数组中所有值的参数
如果不为 null,则用于确定将使用哪些字段 (数组|null)
方法 createContainer()
使用未来。它创建一个容器。
参数
- $width 参数 $width ()
- $height 参数 $height ()
方法 getValueAsArray()
它获取参数的值作为一个关联数组。
参数
- $fields 如果字段为 null,则返回所有参数,包括 "none"。 (数组|null)
- $asAssocArray (默认值:true) 如果为真,则将值作为关联数组返回
如果为假,则作为索引数组返回。 (布尔值)
方法 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 参数 string $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();
如果有的话,显示当前的 BreadCrumb。
参数
- $showIfEmpty 如果为真,即使为空(空行)也显示面包屑 (布尔值)
如果为假(默认值),如果为空则不显示面包屑。 (布尔值)
方法 showCheck()
在单行中显示标签消息,例如:[ERROR] 错误消息
参数
- $label 参数 string|array $label (字符串|数组)
- $color =['red','yellow','green','white','blue','black','cyan','magenta'][$i] (字符串)
- $content 参数 string|array $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 param 混合 $parameter (混合)
方法 bell()
方法 getCursorPosition()
获取光标当前位置
需要在Windows中安装并配置getCh()可执行文件 示例:
$arr=$this->getCursorPosition(); // [x,y]
方法 showMessageBox()
显示包含两列的消息框。
参数
- $lines (右侧)(字符串|字符串数组)
- $titles (左侧)(字符串|字符串数组)
- $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 如果不为null,则仅显示所有相关参数。(字符串|null)
使用$param->setRelated()设置关系。(字符串|null) - $size 第一列的最小大小(?整数)
方法 setDefaultStream()
参数
- $stream =['stdout','stderr','memory'][$i] (字符串)
方法 setNoColor()
参数
- $noColor 如果 true 则不会显示颜色
如果 false,则显示颜色。(布尔值)
方法 isNoColor()
方法 setNoANSI()
如果为true,则控制台处于旧-cmd模式(无颜色,无utf-8字符等)
参数
- $noANSI param bool $noANSI (布尔值)
方法 isNoANSI()
如果
方法 wrapLine()
它包装一行并返回一行或多行
包装的行不打开或关闭标签。
参数
- $texts 已格式化的文本。(字符串|数组)
- $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 可视表示它考虑视觉长度,false 表示它考虑字符。 (布尔值)
方法 removechar()
移除字符串末尾的可见字符。它忽略了不可见字符(例如颜色)。
参数
- $content 参数 string $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 参数 string $content (字符串)
- $cliOneParam 参数 ?CliOneParam $cliOneParam (?CliOneParam)
方法 colorLess()
删除内容中的所有转义字符
参数
- $content 参数 string $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 // 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); }
因此可以运行
使用用户输入的示例
您可以请求用户的输入。
$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); }
它将显示以下结果
带有游戏的示例
颜色示例
您可以在 颜色类型 中看到可用的标签
$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'));
表格示例
用户输入类型
颜色类型
定义
您可以在以下位置找到类、方法和字段的定义
调试
要激活调试模式,必须将调试字段设置为 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)
- 新方法 clearScreen()
- 新方法 cursorHome()
- 新方法 cursorMove()
- 新方法 bell()
- 新方法 getCursorPosition()
- 修复 修复了一些注释。
-
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 列)或 2 列
- "选项" 忽略大小写。
-
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)时出现的错误
-
1.18 (2022-06-11)
- 添加了 addExtensionFile() 方法
-
1.17 (2022-06-09)
- 修复了与 Linux 相关的许多问题(行数、自动完成等)
-
1.16 (2022-03-25)
- setParam() 允许设置值或值-key
-
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
- 方法initialEndStyle()
- CliOneParam
- 添加了一个相关字段。
- CliOne
-
1.11 (2022-02-22)
- 添加了对STDIN、STDOUT和STDERR的支持。
-
1.10 (2022-02-21)
- [新] 支持旧命令行(cmd.exe)。它会自动激活。
- 它将颜色降级为黑白,并更改UTF-8字符以兼容。
- 此外,在此模式下不显示滚动条和等待光标。
- 有关更多信息,请参阅兼容性。
- [新] 支持旧命令行(cmd.exe)。它会自动激活。
-
1.9 (2022-02-20)
- [新] argumentIsValueKey和memory
- [更改] 更改了createParam()的签名,交换了第二个和第三个参数
-
1.8 (2022-02-20)
- [新] setParam()如果参数未定义,则抛出异常。
- [新] showParamSyntax2()
- [新] CliOneParam::$nameArg 参数名称(用于帮助)
-
1.7 (2022-02-18)
- [修复] 为大多数字段和方法添加了类型提示。
- [新] 为CliOneParam添加了新的setValue()。
-
1.6.1 (2022-02-18)
- [修复] 修复了一个小错误,即当值手动设置时,它仍然被标记为缺失。
-
1.6 (2022-02-18)
- [新] 新方法isParameterPresent()
-
1.5.5 (2022-02-18)
- getParameter()始终返回一个参数,无论它是否存在。
- 您可以使用方法isValid()来检查其有效性。
- setSilentError()可以静默错误输出。
- addhistory()重命名为setAddHistory()
- 要添加新参数,add()将验证键是否已被使用,键是否是其他键的别名,或别名是否已被使用。
- getParameter()始终返回一个参数,无论它是否存在。
-
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() 的新参数
- [新增] 新类型名为 password
-
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 第一个版本