rzuw / lyra-cmd
Lyra 命令行实用工具。要与 Lyra 进行命令行交互,应使用此库。
dev-master
2017-07-26 08:26 UTC
Requires
- ext-mbstring: *
- kevinlebrun/colors.php: ~0.2
This package is not auto-updated.
Last update: 2024-09-29 03:31:10 UTC
README
Lyra 的命令行解释是通过此库实现的。命令行选项将使用内部正则表达式进行解析。此命令行库可用于不同的配置,以满足应用程序的需求。此库基于 Nate Good 的 Commando,并增加了可选参数、多个参数组合和命令调度程序等功能。
要求
Lyra CMD 需要安装 php-mbstring
。
安装
要安装 CMD,有几种选项可用
此库可在 packagist 上找到。因此,您只需将其添加为依赖项。
composer require rzuw/lyra-cmd
您也可以克隆库并使用 autoload
或使用 composer 将其添加为文件系统组件。
{
"repositories": [
{
"type": "path",
"url": "/path-to-git-clone"
}
],
"require": {
"rzuw/lyra-cmd": "*"
}
}
您还可以添加存储库,然后需要 rzuw/lyra-cmd
。
{
"require": {
"rzuw/lyra-cmd": "*"
},
"repositories": [
{
"type": "vcs",
"url": "ssh://git@github.com/uniwue-rz/lyra-cmd.git"
}
]
}
使用方法
要使用命令行,只需创建一个新的实例。
use De\Uniwue\RZ\Lyra\CMD\Command;
$command = new Command();
添加具有参数的不同选项。您还可以将不同的选项链接在一起。
$command = new Command();
// Adds the command --bar with shortcut -b with boolean option.
// This means the command --bar will be on or off when called.
// The default value is set to false
$command->option("b")->aka("bar")->describedAs("The bar command")->boolean()->default(false);
// Adds the command --foo with shortcut with boolean option.
// This command will run the bar in the given class and needs always --bar to be set (on) and a username to be set.
// The command has also an optional part which can be there or not but the command will run nevertheless.
$command->option("f")->aka("foo")->describedAs("The foo command")->boolean()->run("bar")->needs(array("b","u"))
->optionals(array("n"));
$command->option("n")->aka("name")->describedAs("The name of the user")->default("");
// This will a required placeholder for the username option of the foo command,which will be filled by "" default.
$command->option("u")->aka("username")->describedAs("Username to foo")->default("");
然后使用您的类调用命令行运行程序
// $class is the class that has the bar command. This will run the bar command with the optional
// parameter of "n" and needed parameters of "u" and "b".
$command->dispatchCommands($class);
测试和开发
为此组件已配置了 phpunit
配置,因此您可以测试大部分代码。您还可以将您的更改添加到代码中。
许可证
查看 LICENSE 和 CREDIT 文件