malenki/argile
Composer 安装命令:
composer require malenki/argile
包简介
CLI app now easy when using args!
README 文档
README
Create, get, write options and autogenerated help messages for your CLI PHP applications…
Basic usage about values and switches
Quick first simple example with only one switch:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->newSwitch('switch') ->short('s') ->help('I am a very simple switch arg with only short form.') ; $opt->parse(); if($opt->has('switch')) { printf("\"switch\" arg selected!\n"); } exit();
So, if your PHP CLI application is into yourapp executable file, then you can call it like that:
$ yourapp -s
"switch" arg selected!
Without options, calling it will give help message:
$ yourapp
Usage: complex.php [OPTIONS]…
-s I am a very simple switch arg with only short
form.
-h, --help Display this help message and exit
Second example with switch, values, short, long and required options:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->newSwitch('switch') ->short('s') ->help('I am a very simple switch arg with only short form.') ; $opt->newValue('foo') ->required() ->short('f') ->long('foo') ->help('I am a simple required arg with short and long forms.') ; $opt->parse(); if($opt->has('switch')) { printf("\"switch\" arg selected!\n"); } if($opt->has('foo')) { printf("\"foo\" arg selected! Its value is: \"%s\"\n", $opt->get('foo')); } exit();
Advanced usage of values and switches
You can customize variable name into help text of each option:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->newValue('foo') ->required() ->short('f') ->long('foo') ->help('I am a simple required value with short and long forms.', 'FILE') ; //...
You can group options together. Easy, you have to create group, and when you create options, you put the group name has second argument:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->addGroup('one', 'Optional title for first group'); $opt->addGroup('two', 'Optional title for second group'); $opt->newSwitch('switch', 'one') ->short('s') ->help('I am a very simple switch arg with only short form.') ; $opt->newValue('foo', 'one') ->required() ->short('f') ->long('foo') ->help('I am a simple required arg with short and long forms.') ; $opt->newValue('bar', 'two') ->short('b') ->long('bar') ->help('I am a simple arg with short and long forms.') ; //...
Later, if you can help, options will be grouped and group's name is shown if it has one.
Detect and get arguments
Detecting and getting arguments is simple, just use hasArgument() and getArguments() methods respectively. The second one returns an array.
Meta information about CLI app
You can define some informations about your app that will be used into help message:
- Synopsis (you can add several synopsis lines, see example files)
- Version
- Description
More
You can have "flexible" help output message, that fit your terminal width, or you can leave at default with of 80 columns.
If you want this text adjustment, do just following:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->flexible(); // yes, that's all // and add your options and other thing…
You can apply color and bold on labels and options:
use Malenki\Argile\Options as Options; $opt = Options::getInstance(); $opt->labelColor('red'); // color for labels $opt->optColor('red'); // color for options $opt->bold(); // labels and options becomes bold // and add your options and other thing…
Colors’ names are the same as foreground colors defined into Ansi project.
To see Argile in action, please look at examples directory and run scripts inside it!
MIT Open Source License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
malenki/argile 适用场景与选型建议
malenki/argile 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.58k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2013 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「arg」 「optget」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 malenki/argile 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 malenki/argile 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 malenki/argile 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Parser for command line options
Slim starter / Slim skeleton package to boost your development with Slim framework
Generates a trait to help ease the access of custom repo methods
Eco CLI for Laravel .env syncing
PHP Command Line Argument Parser
Arg-Laravel utilities
统计信息
- 总下载量: 6.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-09-01