Skip to content

About

logo

Latest Stable Version Total Downloads License Documentation Status

Minicli is a minimalist, zero-dependency framework for building CLI-centric PHP applications. It provides a structured way to organize your commands, as well as various helpers to facilitate working with command arguments, obtaining input from users, and printing colored output to the terminal. Since version 4.0, Minicli requires PHP 8.1.

Requirements

  • PHP >= 8.1
  • ext-readline to obtain user input

Apart from that, you'll need Composer to install and use Minicli.

Zero Dependencies

Minicli is committed to creating a safer software supply chain ecosystem, that's why we don't bring any chained dependencies with the base minicli/minicli package. Starting from version 3.2.0, we also include SBOM files with every release of Minicli. You can download here our latest SBOM in SPDX format.

The base minicli/minicli package contains everything you need to create a simple command-line PHP application to consume an API, generate some data, or just playing around with the command line in PHP-land. You can always opt to bootstrap your application with the minicli/application template repository, and you are encouraged to share and reuse Minicli commands, but we believe that it should be completely up to you which packages you want your application to depend on.

The base minicli/minicli package has only testing dependencies; these are only installed when you clone Minicli for development.

Note

The minicli/application project template contains the skeleton of a more structured application including tests bootstrapped with PestPHP and a couple official Minicli commands such as the default help command. For a dependency-free experience, you must require minicli/minicli from an existing project, and you'll have the freedom to create your own app structure.

Installation

There are mainly two ways to get started: you can choose to create a project from scratch, which might be a good choice for single command apps or to integrate your command / app within another system, or you can use our application repository template, which sets up a minimal structure with Command Namespaces and Controllers - this is the recommended way if you're creating a new standalone command-line application with Minicli.

Both methods are explained in detail in the Getting Started Guide.

Example Code

The following example shows a simple application with a single command registered as callback under the name test. The command prints output in different colors:

PHP
#!/usr/bin/php
<?php

if(php_sapi_name() !== 'cli') {
    exit;
}

require __DIR__ . '/vendor/autoload.php';

use Minicli\App;

$app = new App([
    'app_path' => [
        __DIR__ . '/app/Command',
    ],
    'theme' => '\Unicorn', 
    'debug' => false,
]);

$app->registerCommand('test', function () use ($app) {
    $app->success('Hello World!' , false);
    $app->info('With Background!' , true);
    $app->error('Quitting!', false);
});

$app->runCommand($argv);

You can run the registered command with: ./minicli test. The output looks like the following:

image

Contributing

We welcome all types of contributions and contributors to Minicli and its adjacent repositories, as long as you stick to our code of conduct and follow our simple contributing guidelines. The TL;DR is:

  • be excellent to each other
  • feel free to ask all the questions
  • keep simplicity always in mind
  • discuss ideas before implementing something big
  • follow the PSR-12 PHP code standards if you are contributing with code

History

Minicli was initially created as an experiment about going dependency-free in the context of PHP. The following tutorials on dev.to compose a series named "Building Minicli", where we created the first version of minicli from scratch:

Note

Minicli has evolved a lot since that series was initially written, with the help of many contributors. Thank you!

Created with Minicli

The following applications were created using Minicli:

  • Librarian - A minimalist file-based CMS / markdown document indexer
  • Dynacover - Dynamic Twitter images and banners
  • GDaisy - php-gd based image templates
  • Minileaf - control your Nanoleaf panels via the CLI