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

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

jbzoo/cli
=========

The framework helps create CLI tools and provides new tools for symfony/console, symfony/process.

7.2.5(7mo ago)7629.3k—2.1%5MITPHPPHP ^8.2CI passing

Since Apr 12Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/JBZoo/Cli)[ Packagist](https://packagist.org/packages/jbzoo/cli)[ RSS](/packages/jbzoo-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (20)Used By (5)

JBZoo / Cli
===========

[](#jbzoo--cli)

[![CI](https://github.com/JBZoo/Cli/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Cli/actions/workflows/main.yml?query=branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/cde79f60f6623accd2d14961b0b46f4ef3ab9be98dbb740d3973faea5b2b61c1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f436c692f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/Cli?branch=master)[![Psalm Coverage](https://camo.githubusercontent.com/f05fbcd1d041bc88e9c1492b2cff6a8962448f1e52cd011f04d277c7da2d1f7d/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f436c692f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/Cli)[![Psalm Level](https://camo.githubusercontent.com/ab4f9090878459f630fcb583a43fac64e78ea5349858217ec23d144e00cf5f40/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f436c692f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/Cli)[![CodeFactor](https://camo.githubusercontent.com/75ab3619785fce2e411f67f25e04bd9052f88f46c5dbfbd48aa8d4f660c6ccc6/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f636c692f6261646765)](https://www.codefactor.io/repository/github/jbzoo/cli/issues)

[![Stable Version](https://camo.githubusercontent.com/32708336e16a8f0f116a2872abf76a16d446f13bc292d83577d40d996a01ace7/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f636c692f76657273696f6e)](https://packagist.org/packages/jbzoo/cli/)[![Total Downloads](https://camo.githubusercontent.com/c32fe56418729bcf2d9ba09b796fe88a377704379694035fbb83f6b8ed250f88/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f636c692f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/cli/stats)[![Dependents](https://camo.githubusercontent.com/922857e2010e05cfc7b8423e635d0868a6a2e0ae31552a7ae6272e42a4e47a3c/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f636c692f646570656e64656e7473)](https://packagist.org/packages/jbzoo/cli/dependents?order_by=downloads)[![GitHub License](https://camo.githubusercontent.com/18f657da92b7d6aa4d1d377d022488eefee0b71b29a460265ce326ac6fa157a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f636c69)](https://github.com/JBZoo/Cli/blob/master/LICENSE)

- [Why?](#why)
- [Live Demo](#live-demo)
    - [Output regular messages](#output-regular-messages)
    - [Progress Bar Demo](#progress-bar-demo)
- [Quick Start - Build your first CLI App](#quick-start---build-your-first-cli-app)
    - [Installing](#installing)
    - [File Structure](#file-structure)
    - [Composer file](#composer-file)
    - [Binary file](#binary-file)
    - [Simple CLI Action](#simple-cli-action)
- [Built-in Functionality](#built-in-functionality)
    - [Sanitize input variables](#sanitize-input-variables)
    - [Rendering text in different colors and styles](#rendering-text-in-different-colors-and-styles)
    - [Verbosity Levels](#verbosity-levels)
    - [Memory and time profiling](#memory-and-time-profiling)
- [Progress Bar](#progress-bar)
    - [Simple example](#simple-example)
    - [Advanced usage](#advanced-usage)
- [Helper Functions](#helper-functions)
    - [Regular question](#regular-question)
    - [Ask user's password](#ask-users-password)
    - [Ask user to select the option](#ask-user-to-select-the-option)
    - [Represent a yes/no question](#represent-a-yesno-question)
    - [Rendering key=&gt;value list](#rendering-keyvalue-list)
- [Easy logging](#easy-logging)
    - [Simple log](#simple-log)
    - [Crontab](#crontab)
    - [Elasticsearch / Logstash (ELK)](#elasticsearch--logstash-elk)
- [Multi processing](#multi-processing)
- [Tips &amp; Tricks](#tips--tricks)
- [Contributing](#contributing)
- [Useful projects and links](#useful-projects-and-links)
- [License](#license)
- [See Also](#see-also)

Why?
----

[](#why)

JBZoo CLI Framework is a powerful PHP library that significantly extends Symfony Console functionality, making it easier and faster to create robust command-line applications. Built for PHP 8.2+, it provides enhanced features for professional CLI development.

### Key Features

[](#key-features)

**Enhanced Progress Bars**

- Advanced progress bars with debugging information and profiling capabilities
- Simple API: `$this->progressBar($items, $callback)` replaces complex Symfony ProgressBar setup
- Real-time memory and performance monitoring during execution
- See [Live Demo](https://asciinema.org/a/601633?autoplay=1&startAt=4)

**Strict Type Conversion**

- Type-safe option parsing with methods like `getOptInt()`, `getOptBool()`, `getOptString()`
- Built-in validation for allowed values and data integrity
- Eliminates common runtime errors from loose type handling

**Professional Output System**

- Simplified output API: `$this->_($message, $level, $context)` instead of verbose Symfony methods
- Rich styling with HTML-like tags: `Error`, `Success`
- Context-aware JSON logging for structured data

**Multiple Output Modes**

- `--output-mode=text` - User-friendly console output (default)
- `--output-mode=cron` - Optimized for crontab logging with timestamps and profiling
- `--output-mode=logstash` - JSON format for ELK Stack integration

**Performance &amp; Debugging**

- Built-in profiling with `--profile` flag showing memory usage and execution time
- Timestamping with `--timestamp` for detailed logging
- Verbosity levels from quiet (`-q`) to debug (`-vvv`)

**Advanced Features**

- Multiprocessing support for parallel execution (not multithreading)
- Interactive helpers for user input, confirmations, and selections
- Error handling with configurable exit codes and output streams

Live Demo
---------

[](#live-demo)

### Output regular messages

[](#output-regular-messages)

[![asciicast](https://camo.githubusercontent.com/d485736a7c08431b17883b97799a1b9fdfeeb9c45c6551e1e88e73149ecc4316/68747470733a2f2f61736369696e656d612e6f72672f612f3630313633332e737667)](https://asciinema.org/a/601633?autoplay=1&startAt=4)

### Progress Bar Demo

[](#progress-bar-demo)

[![asciicast](https://camo.githubusercontent.com/41429cb16fb7cc6746bad732de4ded862931589a129e4fa98c0f15611777a961/68747470733a2f2f61736369696e656d612e6f72672f612f3630313632312e737667)](https://asciinema.org/a/601621?autoplay=1&startAt=2)

Quick Start - Build your first CLI App
--------------------------------------

[](#quick-start---build-your-first-cli-app)

### Installing

[](#installing)

```
composer require jbzoo/cli
```

The simplest CLI application has the following file structure. See the [Demo App](demo) for more details.

### File Structure

[](#file-structure)

```
/path/to/app/
    my-app                      # Binary file (See below)
    composer.json               # Composer file
    /Commands/                  # Commands directory
        Simple.php              # One of the commands (See below)
    /vendor/
        autoload.php            # Composer autoload

```

### Composer file

[](#composer-file)

[./demo/composer.json](demo/composer.json)

 See Details```
{
    "name"        : "vendor/my-app",
    "type"        : "project",
    "description" : "Example of CLI App based on JBZoo/CLI",
    "license"     : "MIT",
    "keywords"    : ["cli", "application", "example"],

    "require"     : {
        "php"       : "^8.2",
        "jbzoo/cli" : "^7.0"
    },

    "autoload"    : {
        "psr-4" : {"DemoApp\\" : ""}
    },

    "bin"         : ["my-app"]
}
```

### Binary file

[](#binary-file)

Binary file: [demo/my-app](demo/my-app)

 See Details```
#!/usr/bin/env php
