Skip to content

About

logo

Latest Stable Version Total Downloads License Documentation Status

Minicli is a minimalist, dependency-free 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.

The new version 3.0 is fully upgraded to support PHP 8+.

Requirements

What does it mean to be dependency-free? It means that you can build a functional CLI PHP application without dozens of nested user-land dependencies. The basic minicli/minicli package has only testing dependencies (only installed when you clone Minicli for development), and a single system requirement:

  • PHP >= 8.0

Note

Note: If you want to obtain user input via prompts, then the readline PHP extension is required as well.

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

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:

#!/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->getPrinter()->success('Hello World!' , false);
    $app->getPrinter()->info('With Background!' , true);
    $app->getPrinter()->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

Building Minicli

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