PHPackages                             toolkit/cli-utils - 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. toolkit/cli-utils

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

toolkit/cli-utils
=================

useful cli tool library of the php

v2.0.5(1y ago)20222.1k—0.5%515MITPHPPHP &gt;8.1.0CI passing

Since May 7Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/php-toolkit/cli-utils)[ Packagist](https://packagist.org/packages/toolkit/cli-utils)[ Docs](https://github.com/php-toolkit/cli-utils)[ RSS](/packages/toolkit-cli-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (43)Used By (15)

CLI Utils
=========

[](#cli-utils)

[![License](https://camo.githubusercontent.com/931e8ed2088c27f633f04e5076d116ddf4b812bbf5a0295447cfea52fdd52cc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6f6c6b69742f636c692d7574696c732e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/65227e7fae37c036fd8164e07a1ffdc8c24f8a7114ab0c07749f14b057871999/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d382e302e302d627269676874677265656e2e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/toolkit/cli-utils)[![Latest Stable Version](https://camo.githubusercontent.com/cebde812df7dba1822fe51c03b27031b4189b6b2578d46a1c2f431186296da0d/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6f6c6b69742f636c692d7574696c732e737667)](https://packagist.org/packages/toolkit/cli-utils)[![Actions Status](https://github.com/php-toolkit/cli-utils/workflows/Unit-tests/badge.svg)](https://github.com/php-toolkit/cli-utils/actions)

Provide some useful utils for the php CLI application.

- Simple CLI arguments and options parser.
- Terminal console color render
- CLI code highlighter
- Build simple CLI application
- CLI ENV information helper

Install
-------

[](#install)

- Required PHP 8.0+

```
composer require toolkit/cli-utils
```

Console color
-------------

[](#console-color)

```
Color::printf('%s world', 'hello');
Color::println('hello world', 'info');
Color::println('hello world', 'error');
Color::println('hello world', 'warning');
Color::println('hello world', 'success');

echo Color::render('hello world', 'success');
```

[![colors](example/images/color-styles.png)](example/images/color-styles.png)

Console log
-----------

[](#console-log)

```
use Toolkit\Cli\Util\Clog;

// run: php example/log.php
foreach (Clog::getLevelNames() as $level) {
    Clog::log($level, "example log $level message");
}
```

[![clog-example](example/images/clog-example.png)](example/images/clog-example.png)

Simple console app
------------------

[](#simple-console-app)

```
use Toolkit\Cli\CliApp;

// run:
// php example/mycmd
// php example/mycmd -i abc --lon def ag1 ag2 ag3
$cmd = CliApp::new('cmd1', 'this is my cli application');
$cmd->addOpt('info', 'i', 'Output some information');
$cmd->addOpt('long-option-name', 'lon', 'this is a long option for command');
$cmd->addArg('arg1', 'this is first argument');

$cmd->setHandler(function (CliApp $cmd) {
  var_dump($cmd->getOpts(), $cmd->getArgs(), $cmd->getRemainArgs());
});

$cmd->run();
```

[![clog-example](example/images/cli-app.png)](example/images/cli-app.png)

Terminal control
----------------

[](#terminal-control)

examples:

```
use Toolkit\Cli\Util\Terminal;

Terminal::forward(3);
Terminal::backward(2);

Terminal::clearLine();

Terminal::clearScreen();
```

### Control Methods

[](#control-methods)

```
/**
 * @method static showCursor()
 * @method static hideCursor()
 * @method static savePosition()
 * @method static restorePosition()
 * @method static toTop()
 * @method static toColumn(int $step)
 * @method static up(int $step = 1)
 * @method static down(int $step = 1)
 * @method static forward(int $step = 1)
 * @method static backward(int $step = 1) Moves the terminal cursor backward
 * @method static toPrevNLineStart(int $step = 1)
 * @method static toNextNLineStart(int $step = 1)
 * @method static coordinate(int $col, int $row = 0)
 * @method static clearScreen()
 * @method static clearLine()
 * @method static clearToScreenBegin()
 * @method static clearToScreenEnd()
 * @method static scrollUp(int $step = 1)
 * @method static scrollDown(int $step = 1)
 * @method static showSecondaryScreen()
 * @method static showPrimaryScreen()
 */
```

PHP file highlight
------------------

[](#php-file-highlight)

> This is inspire `jakub-onderka/php-console-highlighter`

```
use Toolkit\Cli\Util\Highlighter;

// this is an comment
$rendered = Highlighter::create()->highlight(file_get_contents(__FILE__));

\Toolkit\Cli\Cli::write($rendered);
```

[![colors](example/cli-php-file-highlight.png)](example/cli-php-file-highlight.png)

CLI downloader
--------------

[](#cli-downloader)

```
use Toolkit\Cli\Download;

$url  = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2';
$down = Download::file($url, '');

// $down->setShowType('bar');
// $down->setDebug(true);
$down->start();
```

**Progress bar**

[![down-file-bar](./example/down-file-bar.jpg)](./example/down-file-bar.jpg)

**Progress text**

[![down-file-txt-bar](./example/down-file-txt-bar.jpg)](./example/down-file-txt-bar.jpg)

Projects
--------

[](#projects)

-  Build rich console application
-  Generic flags parse library, build simple console application.

Refer
-----

[](#refer)

-

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance60

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.7% 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

Every ~62 days

Recently: every ~304 days

Total

42

Last Release

394d ago

Major Versions

v1.2.14 → v2.0.02021-12-01

PHP version history (4 changes)v1.0.0PHP &gt;7.0.0

v1.0.2PHP &gt;7.1.0

v2.0.0PHP &gt;8.0.0

v2.0.4PHP &gt;8.1.0

### Community

Maintainers

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

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (132 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![bjauy](https://avatars.githubusercontent.com/u/1352357?v=4)](https://github.com/bjauy "bjauy (1 commits)")

---

Tags

cli-utilitiescolorhighlightterminalphpclicommand-linelibrarytoolcli-color

### Embed Badge

![Health badge](/badges/toolkit-cli-utils/health.svg)

```
[![Health](https://phpackages.com/badges/toolkit-cli-utils/health.svg)](https://phpackages.com/packages/toolkit-cli-utils)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815412.0k48](/packages/nunomaduro-laravel-console-menu)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2582.1M11](/packages/nunomaduro-laravel-console-task)[nunomaduro/laravel-console-summary

A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.

662.0M3](/packages/nunomaduro-laravel-console-summary)[nunomaduro/laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.

16255.4k7](/packages/nunomaduro-laravel-console-dusk)[rahul900day/laravel-console-spinner

Laravel Console Spinner is a spinner output for Laravel command line.

76125.4k1](/packages/rahul900day-laravel-console-spinner)

PHPackages © 2026

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