PHPackages                             pointybeard/php-cli-lib - 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. pointybeard/php-cli-lib

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

pointybeard/php-cli-lib
=======================

Collection of helpful classes to use when working on the command line (cli).

1.1.0(7y ago)06111MITPHPPHP &gt;=7.2

Since Dec 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/pointybeard/php-cli-lib)[ Packagist](https://packagist.org/packages/pointybeard/php-cli-lib)[ RSS](/packages/pointybeard-php-cli-lib/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (1)

PHP Command Line Interface (CLI) Library
========================================

[](#php-command-line-interface-cli-library)

- Version: v1.1.0
- Date: April 5th 2019
- [Release notes](https://github.com/pointybeard/php-cli-lib/blob/master/CHANGELOG.md)
- [GitHub repository](https://github.com/pointybeard/php-cli-lib)

Collection of helpful classes to use when working on the command line (cli).

Installation
------------

[](#installation)

This library is installed via [Composer](http://getcomposer.org/). To install, use `composer require pointybeard/php-cli-lib` or add `"pointybeard/php-cli-lib": "~1.1"` to your `composer.json` file.

And run composer to update your dependencies:

```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

```

Usage
-----

[](#usage)

This library is broken into 3 distinct components: Message, Prompt, and Argument. They can be used as needed, although they do rely on each other internally.

### Message

[](#message)

```
use CLILib\Message;

## Display a message to STDOUT
(new Message)
    ->message("This is my message")
    ->prependDate(true)
    ->dateFormat('G:i:s > ')
    ->appendNewLine(true)
    ->foreground("light green")
    ->background("red")
    ->display(STDOUT)
;
```

### Prompt

[](#prompt)

```
use CLILib\Prompt;
use CLILib\Message;

// Most basic usage
$name = Prompt::display(
    "Please enter your name"
);
## > Please enter your name:
## >

// Asking for a password
$password = Prompt::display(
    "Please enter your password", Prompt::FLAG_SILENT
);
## > Please enter your password:
## >

// Providing a Message object and default value
$message = (new Message)
    ->message("Enter database user name")
    ->prependDate(false)
    ->appendNewLine(false)
    ->foreground("light green")
    ->background("red")
;
$databaseUserName = Prompt::display(
    $message, null, "root",
);
## > Enter database user name [root]:
## >

// Using a validator to check the input
$user = Prompt::display(
    "Enter your user name", null, null, function($input){
        if(strlen(trim($input)) == 0) {
            (new Message
                ->message("Error: You must enter a user name!")
                ->prependDate(false)
                ->appendNewLine(true)
                ->foreground("red")
            ;
            return false;
        }
        return true;
    }
);
## > Enter your user name:
## >
## > Error: You must enter a user name!
## > Enter your user name:
## >
```

### Argument &amp; Argument/Iterator

[](#argument--argumentiterator)

Include `CLILib\Argument` in your scripts then create an instance of `Argument\Iterator`. It will automatically look for arguments, or you can pass it your own argument string (see below).

#### Syntax Supported

[](#syntax-supported)

This library supports the most common argument formats. Specifically `-x`,` --long`, `/x`. It also supports use of `=` or `:` as a delimiter. The following are examples of supported argument syntax:

```
-x
--aa
--database=blah
-d:blah
--d blah
--database-name=blah
/d blah
-u http://www.theproject.com
-y something
-p:\Users\pointybeard\Sites\shellargs\
-p:"\Users\pointybeard\Sites"
-h:local:host
/host=local-host

```

#### Example

[](#example)

```
use CLILib\Argument;

// Load up the arguments from $argv. By default
// it will ignore the first item, which is the
// script name
$args = new Argument\Iterator();

// Instead of using $argv, send in an array
// of arguments. e.g. emulates "... -i --database blah"
$args = new Argument\Iterator(false, [
    '-i', '--database', 'blah'
]);

// Arguments can an entire string too [Added 1.0.1]
$args = new Argument\Iterator(false, [
    '-i --database blah'
]);

// Iterate over all the arguments
foreach($args as $a){
    printf("%s => %s" . PHP_EOL, $a->name(), $a->value());
}

// Find a specific argument by name
$args->find('i');

// Find also accepts an array of values, returning the first one that is valid
$args->find(['h', 'help', 'usage']);
```

Running the Test Suite
----------------------

[](#running-the-test-suite)

You can check that all code is passing by running the following command from the shell-args folder:

```
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ArgumentsTest

```

If you want to run code coverage (e.g. `--coverage-html tests/reports/ ...`) you'll to install xdebug:

```
pecl channel-update pecl.php.net
pecl install xdebug

```

Support
-------

[](#support)

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/pointybeard/php-cli-lib/issues), or better yet, fork the library and submit a pull request.

Contributing
------------

[](#contributing)

We encourage you to contribute to this project. Please check out the [Contributing documentation](https://github.com/pointybeard/php-cli-lib/blob/master/CONTRIBUTING.md) for guidelines about how to get involved.

License
-------

[](#license)

"PHP Command Line Interface (CLI) Library" is released under the [MIT License](http://www.opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~35 days

Total

5

Last Release

2584d ago

Major Versions

1.1.0 → 2.0.x-dev2019-04-20

PHP version history (2 changes)1.0.0PHP ^5.6

1.1.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![pointybeard](https://avatars.githubusercontent.com/u/24912?v=4)](https://github.com/pointybeard "pointybeard (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pointybeard-php-cli-lib/health.svg)

```
[![Health](https://phpackages.com/badges/pointybeard-php-cli-lib/health.svg)](https://phpackages.com/packages/pointybeard-php-cli-lib)
```

###  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)
