danbettles/command-line-tools
Composer 安装命令:
composer require danbettles/command-line-tools
包简介
Comprises just a few basic classes that make it easier to write command-line scripts. Use this when the might of something like Symfony Console would be like taking a sledgehammer to a thumbtack.
README 文档
README
Skip to installation instructions.
This library comprises just a few basic classes that make it easier to write command-line PHP scripts. There are helpers for running external programs, and methods for sending formatted messages to the output. Use this library when the might of something like Symfony Console would be like taking a sledgehammer to a thumbtack.
The main component classes are Output, MessageFormatter, and Host.
Output
Displays messages on the screen; it provides methods that output messages in different styles.
For example:
(new Output())->writeLine('A plain-looking message followed by a newline.'); (new Output())->danger('A brightly-coloured message about something that just went wrong, followed by a newline.');
Run php tests/show_output_formats.php to see what Output can do.
MessageFormatter
Provides a fluent interface for creating formatted messages. It uses a CSS-like approach, using CSS naming conventions whenever possible, to make the job easier, more intuitive, for web developers.
For example, both of the following calls will create the same bold white message on a bright red background.
$formattedMessage = (new MessageFormatter()) ->fontWeight('bold') ->backgroundColor('maroon') ->format('A brightly-coloured message about something that just went wrong') ; $formattedMessage = MessageFormatter::createFromStyleDeclarations([ 'font-weight' => 'bold', 'background-color' => 'maroon', ])->format('A brightly-coloured message about something that just went wrong');
When creating a Formatter from an array of style declarations, you can use either CSS-style kebab-case names or camel-case names.
MessageFormatterwill automatically use a contrasting colour for the foreground if only the background colour is set.
See the section on the available styles, below, to see what you can do.
Style Reference
| Property | Formatter Method | Valid Values |
|---|---|---|
visibility1 |
visibility |
hidden|visible |
font-weight |
fontWeight |
normal|bold|thin2 |
font-style |
fontStyle |
normal|italic1 |
text-decoration |
textDecoration |
none|underline |
color3 |
color |
initial|teal|aqua|black|gray|navy|blue|purple|fuchsia|green|lime|maroon|red|olive|yellow|silver|white |
background-color3 |
backgroundColor |
initial|teal|aqua|black|gray|navy|blue|purple|fuchsia|green|lime|maroon|red|olive|yellow|silver|white |
Run php tests/show_styles.php to see the effect of each of the style settings—and whether or not a style is supported by your terminal.
Host
Provides a helpful passthru() wrapper that echoes the command it's executing in addition to its output, and, by default, throws an exception if something goes wrong.
For example:
$output = new Output(); $host = new Host($output); // Throws an exception if something goes wrong. $host->passthru('ls -al --color=always'); // Will not throw an exception if something goes wrong: instead, will display a formatted error message and return a value indicating the problem that occurred. $resultCode = $host->passthru('ls -al --color=always', false);
Installation
No dependencies other than PHP 7+.
Install using Composer by running composer require danbettles/command-line-tools.
References
- Fabien Loison (9 Aug 2018) Bash tips: Colors and formatting (ANSI/VT100 Control sequences) https://misc.flogisoft.com/bash/tip_colors_and_formatting Accessed 16 Nov 2022
- Wikipedia (9 Nov 2022) ANSI escape code https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit Accessed 16 Nov 2022
- Chris Maunder (7 Apr 2022) How to change text color in a Linux terminal CodeProject. https://www.codeproject.com/Articles/5329247/How-to-change-text-color-in-a-Linux-terminal Accessed 16 Nov 2022
- MDN Web Docs (27 Sep 2022) font-weight Mozilla. https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping Accessed 16 Nov 2022
- MDN Web Docs (5 Oct 2022) <named-color> Mozilla. https://developer.mozilla.org/en-US/docs/Web/CSS/named-color#value Accessed 16 Nov 2022
Footnotes
danbettles/command-line-tools 适用场景与选型建议
danbettles/command-line-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 danbettles/command-line-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danbettles/command-line-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2022-11-25