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

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

enxebre/cli-generator
=====================

CliGenerator (command-line interface generator) is a library that complements the Symfony Console Component providing a tool for generating loads of commands dynamically from a given source

311PHP

Since Sep 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/enxebre/cliGenerator)[ Packagist](https://packagist.org/packages/enxebre/cli-generator)[ RSS](/packages/enxebre-cli-generator/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

CliGenerator is a tool for creating cli from configuration files (.json, .yaml, etc.) extending [Console Symfony Component](https://github.com/symfony/Console)
===============================================================================================================================================================

[](#cligenerator-is-a-tool-for-creating-cli-from-configuration-files-json-yaml-etc-extending-console-symfony-component)

[![Build Status](https://camo.githubusercontent.com/787dc7c3cdefd90eeac96d521153b98e455f9c70273d2c73a80044219f7b4348/68747470733a2f2f7472617669732d63692e6f72672f656e78656272652f436c6947656e657261746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/enxebre/CliGenerator)

CliGenerator (command-line interface generator) is a library that complements the Symfony Console Component providing a tool for generating loads of commands dynamically from a given source (.json file, method returning an array, .yaml file, etc.).

This library is on [packagist](https://packagist.org/packages/enxebre/cli-generator)

### Installing via Composer

[](#installing-via-composer)

The recommended way to install CliGenerator is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

Adding CliGenerator: Add to your current composer.json `require` key: `"enxebre/cli-generator":"1.0.*" `

After installing, you need to require Composer's autoloader:

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

\##Usage##

```
$cliManager = new cliManager(new cliDiscovery(new cliYourResourceBuilder($your_source_file)), $YourcliClassName);

$application = new Application();
$application->addCommands($cliManager->generateCli());
$application->run();
```

All you need to do is to create a "CliManager" Class and pass the generated commands to your console application like in the example above.

You should implement the "CliResourceBuilderInterface" interface for returning the definitions that will be used for your "CustomCli" Class for building the load of commands.

\##Example##

Some use cases would be a REST API Cli ( you could use [Guzzle](https://github.com/guzzle/guzzle)) or a Database Cli among others.

Dynamic Calculator Cli: The next one is an example tested in the library suite tests. See CliCalculatorTest.php

Definition:

```
{
    "absolute":
    {
        "name":"calculator:abs",
        "description":"Absolute value.",
        "operator":"abs",
        "parameters":
        {
            "value1":{
                "description":"first value"
            }
        }
    },
    "maximum":
    {
        "name":"calculator:max",
        "description":"Maximum of params.",
        "operator":"max",
        "parameters":
        {
            "value1":
            {
                "description":"first value"
            },
            "value2":
            {
                "description":"second value"
            }
        }
    },
    "minimum":
    {
        "name":"calculator:min",
        "description":"Minimum of params.",
        "operator":"min",
        "parameters":
        {
            "value1":
            {
                "description":"first value"
            },
            "value2":
            {
                "description":"second value"
            }
        }
    },
    "Cosine":
    {
        "name":"calculator:cos",
        "description":"Cosine calculator.",
        "operator":"cos",
        "parameters":
        {
            "value1":
            {
                "description":"first value"
            }
        }
    },
    "Sin":
    {
        "name":"calculator:sin",
        "description":"Sine of params.",
        "operator":"sin",
        "parameters":
        {
            "value1":
            {
                "description":"first value"
            }
        }
    },
    "Tan":
    {
        "name":"calculator:tan",
        "description":"Tangent calculator.",
        "operator":"tan",
        "parameters":
        {
            "value1":
            {
                "description":"first value"
            }
        }
    }
}
```

Resource builder:

```
Class CalculatorResourceBuilder implements CliResourceBuilderInterface
{

    private $source;

    /**
     * @param mixed $source
     */
    public function setSource($source)
    {
        $this->source = $source;
    }

    /**
     * @return mixed
     */
    public function getSource()
    {
        return $this->source;
    }
    /**
     * Constructor.
     *
     * @param null $source The source where live our cli definitions.
     */
    public function __construct($source = '/CalculatorDefinition.json') {
        $this->setSource(dirname(__FILE__) . $source);
    }

    /**
     * Responsible for parser a given source and turning
     * it into an array usable by a custom comand class.
     *
     * @return array of the definitions
     *
     * @api
     */
    public function buildDefinitions() {

        $jsonDefinition = file_get_contents($this->getSource());
        $arrayDefinition = json_decode($jsonDefinition, TRUE);
        return $arrayDefinition;
    }
}
```

Custom Cli class:

```
class CalculatorCli extends \CliGenerator\CliBase
{

    private $operator = '';

    /**
     * @param string $operator
     */
    public function setOperator($operator)
    {
        $this->operator = $operator;
    }

    /**
     * @return string
     */
    public function getOperator()
    {
        return $this->operator;
    }

    protected function configure()
    {

        $definition = $this->getCommandDefinition();
        $this
            ->setDescription($definition['description'])
        ;

        $this->setOperator($definition['operator']);

        foreach($definition['parameters'] as $param => $details) {
            $this->addArgument(
                $param,
                null,
                "Introduce a ${details['description']}."
            );
        }
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

        $operator = $this->getOperator();

        if ($input->hasArgument('value2')) {
            $result = $operator($input->getArgument('value1'), $input->getArgument('value2'));
        }
        else {
            $result = $operator($input->getArgument('value1'));
        }

        $output->write($result);

    }
}
```

You could now add as many commands as you want to your CLI just modifying the definition.json file.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ee7c3eda4be70d0fb392bb7df688f7dea4b350ac39d09d9870b18b5d072b47f0?d=identicon)[enxebre](/maintainers/enxebre)

---

Top Contributors

[![enxebre](https://avatars.githubusercontent.com/u/1230698?v=4)](https://github.com/enxebre "enxebre (3 commits)")

### Embed Badge

![Health badge](/badges/enxebre-cli-generator/health.svg)

```
[![Health](https://phpackages.com/badges/enxebre-cli-generator/health.svg)](https://phpackages.com/packages/enxebre-cli-generator)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M319](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M18](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

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