ekowabaka/clearice
Composer 安装命令:
composer require ekowabaka/clearice
包简介
A tool to help in the building of CLI apps. Provides command line parsing and simple console I/O interfaces.
README 文档
README
ClearIce provides tools for PHP applications to help with parsing command line arguments, and performing interactive I/O sessions. Arguments supplied at the command line or through a shell are validated and supplied to your script in a consistently organized format. And gues what, there's also the added possibility of automatically generating help messages for your applications.
Installing
Although you can directly include the ClearIce scripts into your application, the best way of installing it is through composer.
composer require ekowabaka/clearice
ClearIce has no dependencies other than a PHP interpreter with version 7.1 or better.
Parsing Arguments with ClearICE
Let's get started with an example. If you ever wanted to parse command line arguments you can put ...
<?php require "vendor/autoload.php"; $parser = new \clearice\argparser\ArgumentParser(); $parser->addOption([ 'name' => 'input', 'short_name' => 'i', 'type' => 'string', 'required' => true ]); $parser->addOption([ 'name' => 'output', 'short_name' => 'o', 'type' => 'string', 'default' => '/default/output/path' ]); $options = $parser->parse($argv); print_r($options);
... in a file (which you can for example save as wiki.php). Then when you execute ...
php wiki.php generate --input=/home/james --output=/var/www/cool-wiki
... the output will be ...
Array
(
[input] => /input/path
[output] => /output/path
[__executed] => wiki.php
)
... and so will the following:
php test.php --input /input/path --output /output/path
php test.php -i/input/path -o/output/path
Interactive I/O with ClearICE
If you are interested in interactive I/O, entering this
use clearice\io\Io; $io = new Io(); $name = $io->getResponse('What is your name', ['default' => 'No Name']); $direction = $io->getResponse("Okay $name, where do you want to go", [ 'required' => true, 'answers' => array('north', 'south', 'east', 'west') ] );
could lead to an interaction like this:
What is your name [No Name]: ⏎
Okay No Name, where do you want to go (north/south/east/west) []: ⏎
A value is required.
Okay No Name, where do you want to go (north/south/east/west) []: home⏎
Please provide a valid answer.
Okay No Name, where do you want to go (north/south/east/west) []:
Hope you enjoy using ClearIce!
ekowabaka/clearice 适用场景与选型建议
ekowabaka/clearice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.49k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ekowabaka/clearice 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ekowabaka/clearice 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 20
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-29