PHPackages                             danbettles/command-line-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. danbettles/command-line-tools

ActiveLibrary[CLI &amp; Console](/categories/cli)

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.

v1.0.0-beta.1(3y ago)01ISCPHPPHP ^7.4|^8.1.3

Since Nov 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/danbettles/command-line-tools)[ Packagist](https://packagist.org/packages/danbettles/command-line-tools)[ RSS](/packages/danbettles-command-line-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Command-Line Tools
==================

[](#command-line-tools)

[Skip to installation instructions](#installation).

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](https://symfony.com/doc/current/components/console.html) would be like taking a sledgehammer to a thumbtack.

The main component classes are [`Output`](#output), [`MessageFormatter`](#messageformatter), and [`Host`](#host).

`Output`
--------

[](#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`
------------------

[](#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.

> `MessageFormatter` will automatically use a contrasting colour for the foreground if only the background colour is set.

See the [section on the available styles](#style-reference), below, to see what you can do.

### Style Reference

[](#style-reference)

PropertyFormatter MethodValid Values`visibility`[1](#user-content-fn-1-d106e474587586cc9512c1c7a4036e8b)`visibility``hidden|visible``font-weight``fontWeight``normal|bold|thin`[2](#user-content-fn-2-d106e474587586cc9512c1c7a4036e8b)`font-style``fontStyle``normal|italic`[1](#user-content-fn-1-d106e474587586cc9512c1c7a4036e8b)`text-decoration``textDecoration``none|underline``color`[3](#user-content-fn-3-d106e474587586cc9512c1c7a4036e8b)`color``initial|teal|aqua|black|gray|navy|blue|purple|fuchsia|green|lime|maroon|red|olive|yellow|silver|white``background-color`[3](#user-content-fn-3-d106e474587586cc9512c1c7a4036e8b)`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`
------

[](#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
------------

[](#installation)

No dependencies other than PHP 7+.

Install using Composer by running `composer require danbettles/command-line-tools`.

References
----------

[](#references)

- Fabien Loison (9 Aug 2018) *Bash tips: Colors and formatting (ANSI/VT100 Control sequences)* [https://misc.flogisoft.com/bash/tip\_colors\_and\_formatting](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](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.  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](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) *&lt;named-color&gt;* Mozilla.  Accessed 16 Nov 2022

Footnotes
---------

1. Not widely supported by terminals. [↩](#user-content-fnref-1-d106e474587586cc9512c1c7a4036e8b) [↩2](#user-content-fnref-1-2-d106e474587586cc9512c1c7a4036e8b)
2. Non-standard name. [↩](#user-content-fnref-2-d106e474587586cc9512c1c7a4036e8b)
3. Responds to CSS Level-1 named colours. [↩](#user-content-fnref-3-d106e474587586cc9512c1c7a4036e8b) [↩2](#user-content-fnref-3-2-d106e474587586cc9512c1c7a4036e8b)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1274d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb4422c02b29b1ae4a4746abb1ebf16c0216d5fc62cf0604e7c6aa4de974b39b?d=identicon)[danbettles](/maintainers/danbettles)

---

Top Contributors

[![danbettles](https://avatars.githubusercontent.com/u/736672?v=4)](https://github.com/danbettles "danbettles (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/danbettles-command-line-tools/health.svg)

```
[![Health](https://phpackages.com/badges/danbettles-command-line-tools/health.svg)](https://phpackages.com/packages/danbettles-command-line-tools)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
