yahvya/php-cli-tool-builder
Composer 安装命令:
composer require yahvya/php-cli-tool-builder
包简介
PHP library which helps to build cli php scripts
README 文档
README
A lightweight library to build your own custom CLI scripts.
📄 Library Details
- 👤 Author and maintainer: Yahaya Bathily - GitHub
- 📄 License: MIT
- 🧾 License usage: Free to use in both commercial and non-commercial projects under the MIT license.
- 🗓️ Created at: 25/08/2025
📚 Documentation
The steps to create your own scripts are as follows:
- Create your command classes by implementing the
CliCommandinterface - Create the script file
- Load your autoload file
- Create an instance of the
CliToolBuilderclass with the expected configuration like bellow - Call the treat input method with the arguments of the script as a parameter (you can simulate your arguments by passing a formated array like
$argv, 'command name' 'arguments...')
<?php
use Yahvya\PhpCliToolBuilder\Builder\CliToolBuilder;
use Yahvya\PhpCliToolBuilder\Builder\CliToolConfiguration;
use Yahvya\PhpCliToolBuilder\Default\Command\HelpCommand;
require_once(__DIR__ . "/vendor/autoload.php");
$cliToolBuilder = new CliToolBuilder(
configuration: new CliToolConfiguration(
toolName: "cli-lib",
toolDescription: "A tool to help you build your cli tool",
toolVersion: "1.0.0",
toolAuthor: "Yahvya",
commands: [
new HelpCommand()
]
)
);
try
{
$cliToolBuilder->treatInput(cliArguments: $argv);
}
catch(Exception $e)
{
echo $e->getMessage();
}
There are also some 'traits' available under the Yahvya\PhpCliToolBuilder\Power namespace that you can use to develop your commands quickly.
SearchArgumentPower: allows searching arguments in different ways
✅ Library Test Coverage
To run the tests, clone the repository and run:
php vendor/bin/phpunit
Code Coverage Report
Code Coverage Report:
2025-08-25 20:06:29
Summary:
Classes: 66.67% (2/3)
Methods: 60.00% (3/5)
Lines: 59.46% (22/37)
Yahvya\PhpCliToolBuilder\Builder\CliToolBuilder
Methods: 33.33% ( 1/ 3) Lines: 53.12% ( 17/ 32)
Yahvya\PhpCliToolBuilder\Builder\CliToolConfiguration
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 1/ 1)
Yahvya\PhpCliToolBuilder\Power\SearchArgumentPower
Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 4/ 4)
🙌 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
📫 Contact
If you have any questions or suggestions, feel free to reach out via GitHub.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-25