PHPackages                             kilylabs/cliframework - 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. [Framework](/categories/framework)
4. /
5. kilylabs/cliframework

ActiveLibrary[Framework](/categories/framework)

kilylabs/cliframework
=====================

Command-line framework for PHP

4.0.0.3(5y ago)0761MITPHPPHP &gt;=5.3.0

Since May 11Pushed 5y agoCompare

[ Source](https://github.com/kilylabs/CLIFramework)[ Packagist](https://packagist.org/packages/kilylabs/cliframework)[ Docs](http://github.com/kilylabs/CLIFramework)[ RSS](/packages/kilylabs-cliframework/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (3)Dependencies (8)Versions (70)Used By (1)

CLIFramework
============

[](#cliframework)

**IT IS NOT ORIGINAL REPO BUT FORKED FROM . WE JUST FIXED A FEW BUGS**

[![Build Status](https://camo.githubusercontent.com/cdf05bbd3251cf414aab7073a7ad818a1f82348bde514ba5a40f12007a713cb6/68747470733a2f2f7472617669732d63692e6f72672f6339732f434c494672616d65776f726b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/c9s/CLIFramework)[![Coverage Status](https://camo.githubusercontent.com/44d3668fb1a9546ae1320555e96130ec5ea19fb8695fa3b8fcfa9ad38a17ca0d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6339732f434c494672616d65776f726b2e737667)](https://coveralls.io/r/c9s/CLIFramework)[![Latest Stable Version](https://camo.githubusercontent.com/1869573378a581ac4b2d143d5bcf99dd5a21d16e1f90d6efdd42f8492203dfe8/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636c696672616d65776f726b2f762f737461626c652e737667)](https://packagist.org/packages/corneltek/cliframework)[![Latest Unstable Version](https://camo.githubusercontent.com/7e9164ad298c2801a6faac890d50990a4f80930b15e8a53e9587b78d57de9bdc/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636c696672616d65776f726b2f762f756e737461626c652e737667)](https://packagist.org/packages/corneltek/cliframework)[![Total Downloads](https://camo.githubusercontent.com/f00640f056a9b4a889d5ce58dae3f807a10470b9f82ce8c1feb1b230c281ab69/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636c696672616d65776f726b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/corneltek/cliframework)[![Monthly Downloads](https://camo.githubusercontent.com/863e4835b30718ee7b01e828db43b11ef80f49770d60da94407cf93fa6f77140/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636c696672616d65776f726b2f642f6d6f6e74686c79)](https://packagist.org/packages/corneltek/cliframework)[![License](https://camo.githubusercontent.com/65683ecb1b93c228f7ef2a8022ff87a2d169ef9776421b552f12b6e32b9a3a47/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f636c696672616d65776f726b2f6c6963656e73652e737667)](https://packagist.org/packages/corneltek/cliframework)

CLIFramework is a command-line application framework, for building flexiable, simple command-line applications.

Commands and Subcommands can be registered from outside of an application or your plugins.

Defining a new command is pretty simple, all you need to is declare a class which is inherited from `CLIFramework\Command` class.

Features
--------

[](#features)

- Intuitive command class and option spec
- command options are supported, powered by GetOptionKit. including long option, short option, required|optional|default value.
- Hierarchical commands.
- Automatic help page generation.
- Automatic zsh completion generator.
- Automatic bash completion generator.
- Friendly message when command arguments are not enough.
- Testable, CLIFramework provides PHPUnit test case for testing the commands in PHP.
- Argument validation, suggestion,
- Command Groups
- HHVM compatible

Synopsis
--------

[](#synopsis)

```
class CommitCommand extends CLIFramework\Command {

    public function brief() { return 'brief of bar'; }

    public function options($opts) {
        $opts->add('C|reuse-message:','Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.')
            ->isa('string')
            ->valueName('commit hash')
            // ->validValues([ 'static-50768ab', 'static-c2efdc2', 'static-ed5ba6a', 'static-cf0b1eb'])
            ->validValues(function() {
                $output = array();
                exec("git rev-list --abbrev-commit HEAD -n 20", $output);
                return $output;
            })
            ;

        // Runtime completion by setting up a closure for completion
        $opts->add('c|reedit-message:','like -C, but with -c the editor is invoked, so that the user can further edit the commit message.')
            ->isa('string')
            ->valueName('commit hash')
            ->validValues(function() {
                // exec("git log -n 10 --pretty=format:%H:%s", $output);
                exec("git log -n 10 --pretty=format:%H:%s", $output);
                return array_map(function($line) {
                    list($key,$val) = explode(':',$line);
                    $val = preg_replace('/\W/',' ', $val);
                    return array($key, $val);
                }, $output);
            })
            ;

        $opts->add('author:', 'Override the commit author. Specify an explicit author using the standard A U Thor  format.')
            ->suggestions(array( 'c9s', 'foo' , 'bar' ))
            ->valueName('author name')
            ;

        $opts->add('output:', 'Output file')
            ->isa('file')
            ;
    }

    public function arguments($args) {
        $args->add('user')
            ->validValues(['c9s','bar','foo']);

        // Static completion result
        $args->add('repo')
            ->validValues(['CLIFramework','GetOptionKit']);

        // Add an argument info expecting multiple *.php files
        $args->add('file')
            ->isa('file')
            ->glob('*.php')
            ->multiple()
            ;
    }

    public function init() {

        $this->command('foo'); // register App\Command\FooCommand automatically

        $this->command('bar', 'WhatEver\MyCommand\BarCommand');

        $this->commandGroup('General Commands', ['foo', 'bar']);

        $this->commandGroup('Database Commands', ['create-db', 'drop-db']);

        $this->commandGroup('More Commands', [
            'foo' => 'WhatEver\MyCommand\FooCommand',
            'bar' => 'WhatEver\MyCommand\BarCommand'
        ]);
    }

    public function execute($user,$repo) {
        $this->logger->notice('executing bar command.');
        $this->logger->info('info message');
        $this->logger->debug('info message');
        $this->logger->write('just write');
        $this->logger->writeln('just drop a line');
        $this->logger->newline();

        return "Return result as an API"; // This can be integrated in your web application
    }
}
```

### Automatic Zsh Completion Generator

[](#automatic-zsh-completion-generator)

[![Imgur](https://camo.githubusercontent.com/3f2675a70fd16e969ae8b92d29f8c37683a3aedce6054598eff64aafc564b035/687474703a2f2f696d6775722e636f6d2f7355336d7244652e676966)](https://camo.githubusercontent.com/3f2675a70fd16e969ae8b92d29f8c37683a3aedce6054598eff64aafc564b035/687474703a2f2f696d6775722e636f6d2f7355336d7244652e676966)

#### Zsh Completion With Lazy Completion Values:

[](#zsh-completion-with-lazy-completion-values)

[![Imgur](https://camo.githubusercontent.com/12f849b490bb3ac9dc792a405afbcd72f25ba140125ac57641be7d96b4cb9a79/687474703a2f2f692e696d6775722e636f6d2f497459474449752e676966)](https://camo.githubusercontent.com/12f849b490bb3ac9dc792a405afbcd72f25ba140125ac57641be7d96b4cb9a79/687474703a2f2f692e696d6775722e636f6d2f497459474449752e676966)

#### Bash Completion

[](#bash-completion)

[![Imgur](https://camo.githubusercontent.com/f6ec14d2e687b69e3f7bc107258b7ab05abe1d5aee8fd8dfb8068484f64f9424/687474703a2f2f692e696d6775722e636f6d2f734635555058352e676966)](https://camo.githubusercontent.com/f6ec14d2e687b69e3f7bc107258b7ab05abe1d5aee8fd8dfb8068484f64f9424/687474703a2f2f692e696d6775722e636f6d2f734635555058352e676966)

Documentation
-------------

[](#documentation)

See documentation on our wiki

Command Forms
-------------

[](#command-forms)

CLIFramework supports many command-line forms, for example:

```
$ app [app-opts] [subcommand1] [subcommand1-opts] [subcommand2] [subcommand2-opts] .... [arguments]

```

If the subcommand is not defined, you can still use the simple form:

```
$ app [app-opts] [arguments]

```

For example,

```
$ app db schema --clean dbname
$ app gen controller --opt1 --opt2 ControllerName

```

Subcommand Hierarchy
--------------------

[](#subcommand-hierarchy)

Commands have methods for stages, like `prepare`, `execute`, `finish`, for a command like below:

```
$ app foo_cmd bar_cmd arg1 arg2 arg3

```

The call graph is like:

```
app->run
- app->prepare
  - foo_cmd->prepare
    - bar_cmd->prepare
    - bar_cmd->execute
    - bar_cmd->finish
  - foo_cmd->finish
- app->finish

```

Basic Requirement
-----------------

[](#basic-requirement)

- PHP 5.3

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

[](#installation)

From composer

```
{
    "require": {
        "corneltek/cliframework": "*"
    }
}
```

Zsh Completion Generator
------------------------

[](#zsh-completion-generator)

```
example/demo zsh demo > _demo
source _demo
```

```
demo
```

[![Imgur](https://camo.githubusercontent.com/3a5f427d2402ec00ac74a1d52138e89b06e221a1c45a6d2580e1e9c37d57423a/687474703a2f2f696d6775722e636f6d2f424f5a52464a542e706e67)](https://camo.githubusercontent.com/3a5f427d2402ec00ac74a1d52138e89b06e221a1c45a6d2580e1e9c37d57423a/687474703a2f2f696d6775722e636f6d2f424f5a52464a542e706e67)

[![Imgur](https://camo.githubusercontent.com/914632143feffe72f274f0ecbcb81288f9c8a33e70bdc1c72e5c8a2f677a1f07/687474703a2f2f696d6775722e636f6d2f4158556a6931542e706e67)](https://camo.githubusercontent.com/914632143feffe72f274f0ecbcb81288f9c8a33e70bdc1c72e5c8a2f677a1f07/687474703a2f2f696d6775722e636f6d2f4158556a6931542e706e67)

[![Imgur](https://camo.githubusercontent.com/a91acd74a3b8f7030051eadbb9fe1fa5b1155f847b698c662f4e010a396e3913/687474703a2f2f696d6775722e636f6d2f626732505049462e706e67)](https://camo.githubusercontent.com/a91acd74a3b8f7030051eadbb9fe1fa5b1155f847b698c662f4e010a396e3913/687474703a2f2f696d6775722e636f6d2f626732505049462e706e67)

[![Imgur](https://camo.githubusercontent.com/8777e72e6e71c2fedbc6a85a63cb517ea3ac2e9bdec880057b1c1c390fe8edaf/687474703a2f2f696d6775722e636f6d2f444c6d7a4b44342e706e67)](https://camo.githubusercontent.com/8777e72e6e71c2fedbc6a85a63cb517ea3ac2e9bdec880057b1c1c390fe8edaf/687474703a2f2f696d6775722e636f6d2f444c6d7a4b44342e706e67)

Console Prompt (Readline)
-------------------------

[](#console-prompt-readline)

simple prompt:

```
$input = $this->ask("Your name please");
```

```
$ php demo.php
Your name please:

```

prompt and except valid values:

```
$input = $this->ask("Your name please", array('John', 'Pedro'));
```

Version Info
------------

[](#version-info)

CLIFrameword has a built-in --version option, to setup the version info, you can simply override a const in your application class to setup version string:

```
class ConsoleApp extends CLIFramework\Application
{
    const NAME = 'YourApp';
    const VERSION = '1.2.1';
}
```

This shows:

```
$ yourapp.php --version
YourApp - version 1.2.1

```

Example
-------

[](#example)

Please check `example/demo.php`

```
$ php example/demo.php

```

ArgumentEditor
--------------

[](#argumenteditor)

```
use CLIFramework\ArgumentEditor\ArgumentEditor;

$editor = new ArgumentEditor(array('./configure','--enable-debug'));
$editor->append('--enable-zip');
$editor->append('--with-sqlite','--with-postgres');

echo $editor;
# ./configure --enable-debug --enable-zip --with-sqlite --with-postgres
```

Message style formatter
-----------------------

[](#message-style-formatter)

```
$formatter = new CLIFramework\Formatter;
$formatter->format( 'message' , 'green' );
```

Built-in styles:

```
'red'          => array('fg' => 'red'),
'green'        => array('fg' => 'green'),
'white'        => array('fg' => 'white'),
'yellow'       => array('fg' => 'yellow'),
'strong_red'   => array('fg' => 'red', 'bold'  => 1),
'strong_green' => array('fg' => 'green','bold' => 1),
'strong_white' => array('fg' => 'white','bold' => 1),

```

Building Phar Archive file
--------------------------

[](#building-phar-archive-file)

```
COMPOSER=tests/fixture/composer.json.phar-test composer install
php example/demo archive --working-dir /Users/c9s/work/php/CLIFramework \
        --composer tests/fixture/composer.json.phar-test \
        app.phar

```

Chooser Component
-----------------

[](#chooser-component)

```
$chooser = new CLIFramework\Chooser;
$value = $chooser->choose( "System Options" , array(
    'use php-5.4.0' => '5.4.0',
    'use php-5.4.1' => '5.4.1',
    'use system' => '5.3.0',
));
```

Debug Utilities
---------------

[](#debug-utilities)

### LineIndicator

[](#lineindicator)

```
use CLIFramework\Debug\LineIndicator;
$indicator = new LineIndicator;
echo PHP_EOL, $indicator->indicateFile(__FILE__, __LINE__);
```

### ConsoleDebug class

[](#consoledebug-class)

```
use CLIFramework\Debug\ConsoleDebug;

ConsoleDebug::dumpRows($pdo->fetchAll());

ConsoleDebug::dumpException($e);
```

Todos in the next release
-------------------------

[](#todos-in-the-next-release)

- provide a easy way to define chained commands
- inheritable options for subcommands.
- human readable exception renderer.
- interact utilities

Hacking
=======

[](#hacking)

Setup
-----

[](#setup)

1. Download &amp; install Onion from
2. Use Onion to bundle the dependencies:

    $ onion bundle
3. Run tests, it should pass.
4. Hack hack hack.
5. Run tests.
6. Send a pull request.

How command class register works
--------------------------------

[](#how-command-class-register-works)

- CLIApplication is inherited from CommandBase.
- Command is also inherited from CommandBase.
- To register a subcommand, we use the `addCommand` method to register commands or subcommands.
    - The command class is optional, if command class name is omitted, then the `addCommand` method will try to guess the *real* command class, and try to load the command class.

[![Bitdeli Badge](https://camo.githubusercontent.com/c59c53d49a202da51af3dca7d6339d92244c84549d6239cac4799a8e4c995a6e/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f6339732f636c696672616d65776f726b2f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 95.6% 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 ~53 days

Recently: every ~308 days

Total

60

Last Release

1950d ago

Major Versions

1.5.13 → 2.0.x-dev2014-10-04

1.10.2 → 2.0.12014-10-05

2.8.1 → 3.0.02016-06-10

2.5.x-dev → 4.0.02017-08-28

3.0.x-dev → 4.0.0.12020-12-26

PHP version history (2 changes)1.4.0PHP &gt;=5.3.0

2.5.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/223025b69de050a14f15a1368506e86c200b7b0749e08d1e4f701d46dce2abbd?d=identicon)[kilylabs](/maintainers/kilylabs)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (938 commits)")[![dh3014](https://avatars.githubusercontent.com/u/7791644?v=4)](https://github.com/dh3014 "dh3014 (22 commits)")[![marcioAlmada](https://avatars.githubusercontent.com/u/227395?v=4)](https://github.com/marcioAlmada "marcioAlmada (8 commits)")[![igorsantos07](https://avatars.githubusercontent.com/u/532299?v=4)](https://github.com/igorsantos07 "igorsantos07 (2 commits)")[![petrusqui](https://avatars.githubusercontent.com/u/3110483?v=4)](https://github.com/petrusqui "petrusqui (2 commits)")[![paco3346](https://avatars.githubusercontent.com/u/3145247?v=4)](https://github.com/paco3346 "paco3346 (1 commits)")[![ReadmeCritic](https://avatars.githubusercontent.com/u/15367484?v=4)](https://github.com/ReadmeCritic "ReadmeCritic (1 commits)")[![recca0120](https://avatars.githubusercontent.com/u/1390554?v=4)](https://github.com/recca0120 "recca0120 (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![valbendan](https://avatars.githubusercontent.com/u/1709816?v=4)](https://github.com/valbendan "valbendan (1 commits)")[![eimajenthat](https://avatars.githubusercontent.com/u/1080691?v=4)](https://github.com/eimajenthat "eimajenthat (1 commits)")[![GM-Alex](https://avatars.githubusercontent.com/u/1454864?v=4)](https://github.com/GM-Alex "GM-Alex (1 commits)")[![karbowiak](https://avatars.githubusercontent.com/u/337661?v=4)](https://github.com/karbowiak "karbowiak (1 commits)")[![ooxi](https://avatars.githubusercontent.com/u/2611835?v=4)](https://github.com/ooxi "ooxi (1 commits)")

---

Tags

command-lineframeworkcommandgetoptcompletionzsh

### Embed Badge

![Health badge](/badges/kilylabs-cliframework/health.svg)

```
[![Health](https://phpackages.com/badges/kilylabs-cliframework/health.svg)](https://phpackages.com/packages/kilylabs-cliframework)
```

###  Alternatives

[corneltek/cliframework

Command-line framework for PHP

435160.5k16](/packages/corneltek-cliframework)[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[pestphp/pest-plugin-drift

The Pest Drift Plugin

734.0M74](/packages/pestphp-pest-plugin-drift)[utopia-php/cli

A simple CLI library to manage command line applications

41396.4k10](/packages/utopia-php-cli)[ppi/framework

PPI Framework - The PHP Interoperability Framework!

1542.4k6](/packages/ppi-framework)

PHPackages © 2026

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