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

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

webfiori/cli
============

Class library to simplify the process of creating command line based applications using PHP.

v2.1.0(3mo ago)916.5k[1 issues](https://github.com/WebFiori/cli/issues)MITPHPPHP ^8.1CI passing

Since Jul 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/WebFiori/cli)[ Packagist](https://packagist.org/packages/webfiori/cli)[ RSS](/packages/webfiori-cli/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (31)Used By (0)

WebFiori CLI
============

[](#webfiori-cli)

Class library that can help in writing command line based applications with minimum dependencies using PHP.

 [ ![](https://github.com/WebFiori/cli/actions/workflows/php85.yaml/badge.svg?branch=main) ](https://github.com/WebFiori/cli/actions/workflows/php85.yaml) [ ![](https://camo.githubusercontent.com/d3722e9a8ce9edf77e14d4295924ecb319782d353bdcc1ccb3732843fcc15e2c/68747470733a2f2f636f6465636f762e696f2f67682f57656246696f72692f636c692f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/WebFiori/cli) [ ![](https://camo.githubusercontent.com/b621fd56c5368364d3ac4b22bf146341c1d4f287f870c5a2a24baead659444fa/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d57656246696f72695f636c69266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/dashboard?id=WebFiori_cli) [ ![](https://camo.githubusercontent.com/dbcb42f79abc1fb18d77432067f2504eb5120f6d20333a5837f07a7a26842ca9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f57656246696f72692f636c692e7376673f6c6162656c3d6c6174657374) ](https://github.com/WebFiori/cli/releases) [ ![](https://camo.githubusercontent.com/c4f084af2aa74edc7e09f2ffcc05e3454a45486cb627aa334819a2946e1366fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f636c693f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/cli)

Content
-------

[](#content)

- [Supported PHP Versions](#supported-php-versions)
- [Features](#features)
- [Quick Start](#quick-start)
- [Sample Application](#sample-application)
- [Installation](#installation)
- [Basic Usage](#basic-usage)
    - [Simple Command Example](#simple-command-example)
    - [Command with Arguments](#command-with-arguments)
    - [Multi-Command Application](#multi-command-application)
- [Creating and Running Commands](#creating-and-running-commands)
    - [Creating a Command](#creating-a-command)
    - [Running a Command](#running-a-command)
    - [Arguments](#arguments)
        - [Adding Arguments to Commands](#adding-arguments-to-commands)
        - [Accessing Argument Value](#accessing-argument-value)
- [Advanced Features](#advanced-features)
    - [Interactive Mode](#interactive-mode)
    - [Input and Output Streams](#input-and-output-streams)
    - [ANSI Colors and Formatting](#ansi-colors-and-formatting)
    - [Progress Bars](#progress-bars)
    - [Table Display](#table-display)
- [The `help` Command](#the-help-command)
    - [Setting Help Instructions](#setting-help-instructions)
    - [Running `help` Command](#running-help-command)
        - [General Help](#general-help)
        - [Command-Specific Help](#command-specific-help)
- [Unit-Testing Commands](#unit-testing-commands)
- [Examples](#examples)

Supported PHP Versions
----------------------

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/cli/actions/workflows/php81.yaml/badge.svg?branch=main)](https://github.com/WebFiori/cli/actions/workflows/php81.yaml)[![](https://github.com/WebFiori/cli/actions/workflows/php82.yaml/badge.svg?branch=main)](https://github.com/WebFiori/cli/actions/workflows/php82.yaml)[![](https://github.com/WebFiori/cli/actions/workflows/php83.yaml/badge.svg?branch=main)](https://github.com/WebFiori/cli/actions/workflows/php83.yaml)[![](https://github.com/WebFiori/cli/actions/workflows/php84.yaml/badge.svg?branch=main)](https://github.com/WebFiori/cli/actions/workflows/php84.yaml)[![](https://github.com/WebFiori/cli/actions/workflows/php85.yaml/badge.svg?branch=main)](https://github.com/WebFiori/cli/actions/workflows/php85.yaml)Features
--------

[](#features)

- **Easy Command Creation**: Simple class-based approach to building CLI commands
- **Argument Handling**: Support for required and optional arguments with validation
- **Interactive Mode**: Keep your application running and execute multiple commands
- **ANSI Output**: Rich text formatting with colors and styles
- **Input/Output Streams**: Custom input and output stream implementations
- **Progress Bars**: Built-in progress indicators for long-running operations
- **Table Display**: Format and display data in clean, readable tables
- **Help System**: Automatic help generation for commands and arguments
- **Unit Testing**: Built-in testing utilities for command validation
- **Minimal Dependencies**: Lightweight library with minimal external requirements

Quick Start
-----------

[](#quick-start)

Get up and running in minutes:

```
# Install via Composer
composer require webfiori/cli

# Create your first command
php -r "
require 'vendor/autoload.php';
use WebFiori\Cli\Command;
use WebFiori\Cli\Runner;

class HelloCommand extends Command {
    public function __construct() {
        parent::__construct('hello', [], 'Say hello to the world');
    }
    public function exec(): int {
        \$this->println('Hello, World!');
        return 0;
    }
}

\$runner = new Runner();
\$runner->register(new HelloCommand());
exit(\$runner->start());
" hello
```

Sample Application
------------------

[](#sample-application)

A complete sample application with multiple examples can be found here: **[📁 View Sample Application](https://github.com/WebFiori/cli/tree/main/examples)**

The sample application includes:

- **[Basic Commands](https://github.com/WebFiori/cli/tree/main/examples/01-basic-hello-world)** - Simple command creation
- **[Arguments Handling](https://github.com/WebFiori/cli/tree/main/examples/02-arguments-and-options)** - Working with command arguments
- **[User Input](https://github.com/WebFiori/cli/tree/main/examples/03-user-input)** - Building interactive applications
- **[Multi-Command Apps](https://github.com/WebFiori/cli/tree/main/examples/10-multi-command-app)** - Complex applications with multiple commands
- **[Progress Bars](https://github.com/WebFiori/cli/tree/main/examples/07-progress-bars)** - Visual progress indicators
- **[Table Display](https://github.com/WebFiori/cli/tree/main/examples/06-table-display)** - Formatting data in tables
- **[Database Operations](https://github.com/WebFiori/cli/tree/main/examples/09-database-ops)** - Database CLI commands

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

[](#installation)

Install WebFiori CLI using Composer:

```
composer require webfiori/cli
```

Or add it to your `composer.json`:

```
{
    "require": {
        "webfiori/cli": "*"
    }
}
```

Basic Usage
-----------

[](#basic-usage)

### Simple Command Example

[](#simple-command-example)

Create a basic command that outputs a message:

```
