netfocusinc / argh
Argh!PHP 参数助手。轻松解析 PHP CLI 脚本中的所有类型命令行参数。
1.0.3-beta
2019-04-30 21:47 UTC
Requires (Dev)
- phpunit/phpunit: ^7.3
This package is auto-updated.
Last update: 2024-09-29 05:08:34 UTC
README
"Argh" 是 参数助手 的简称。
轻松解析 PHP 命令行参数,以便您专注于 CLI 应用程序。
-
更多关于 Argh 的信息,请访问 Argh!PHP CLI 参数助手
-
详细的文档可以在 Argh!Wiki 中找到
系统需求
本项目已使用以下列表中的软件开发和测试(见下文列表),尚未在其他操作系统或 PHP 版本上进行测试。
- PHP 7.2.14
- CentOS 7.6
安装
安装 Argh 有两种方法。推荐使用 Composer。
- Composer
- Phar(PHP 归档)
更详细的说明请参阅 Argh 安装说明
Composer 安装
Composer 是推荐的安装方法。
$ composer require netfocusinc/argh
$ php vendor/netfocusinc/argh/bin/argh.php about
Argh! by Benjamin Hough, Net Focus Inc. - https://www.netfocusinc.com/argh
Phar(PHP 归档)
可以从 Argh 的 Github 发布版 下载版本。
$ cd path/to/argh
$ php argh.phar about
Argh! by Benjamin Hough, Net Focus Inc. - https://www.netfocusinc.com/argh
基本用法
使用 Argh 是解析 PHP CLI 脚本中命令行参数的简单方法。
当您的 PHP CLI 脚本使用命令行参数调用时 $ php myprogram.php --message='Hello World!'
<?php
include 'vendor/autoload.php';
use netfocusinc\argh\Argh;
use netfocusinc\argh\StringParameter;
// Create a new Argh instance
$argh = new Argh(
[
StringParameter::createWithAttributes( [ 'name' => 'message' ] )
]
);
// Let Argh parse PHP's $argv array
$argh->parse($argv);
// Access run-time values of the arguments that were supplied to your CLI script
echo $argh->message; // Hello World!
有关如何使用 Argh 的更多示例,请参阅 使用 Argh 的示例
运行单元测试
Argh 的 PHPUnit 测试可以这样运行。
- 当 Argh 使用 Composer 安装时
$ vendor/bin/phpunit --bootstrap vendor/autoload.php --testdox tests/
构建工具
- PHP - PHP 是一种流行的通用脚本语言,特别适合于 Web 开发。
- Composer - PHP 的依赖管理器
- PHPUnit - 测试框架
- phar-composer - 简单的 phar 创建工具,适用于任何由 composer 管理的项目。
版本管理
本项目使用 语义版本控制
有关可用版本,请参阅 GitHub 发布页面。
在 Github 上的 变更日志 也可以找到。
作者
查看参与此项目的 贡献者列表。
许可证
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE.md 文件。