PHPackages                             horde/cli\_modular - 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. horde/cli\_modular

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

horde/cli\_modular
==================

Modular command line interface library

v3.0.0beta1(1mo ago)11.1k—2%3[1 issues](https://github.com/horde/Cli_Modular/issues)2LGPL-2.1-onlyPHPPHP ^7.4 || ^8

Since Jan 8Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/horde/Cli_Modular)[ Packagist](https://packagist.org/packages/horde/cli_modular)[ Docs](https://www.horde.org/libraries/Horde_Cli_Modular)[ RSS](/packages/horde-cli-modular/feed)WikiDiscussions FRAMEWORK\_6\_0 Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (12)Used By (2)

Horde\_Cli\_Modular
===================

[](#horde_cli_modular)

Command line interfaces can often be composed of different modules responsible for distinct actions. Horde\_Cli\_Modular allows each such module to influence the overall command line interface.

First and foremost each module can add its own option group with a specific title, description and a set of module specific options (see Horde\_Argv\_OptionGroup for further details). In addition Horde\_Cli\_Modular allows a module to modify the global usage string and add basic options valid for all modules.

Introduction
------------

[](#introduction)

The command line of the tool **pear** is a good example of the kind of interface Horde\_Cli\_Modular supports: There are a number of global options available but each command supported by **pear** may have its own subset of options. **-c** identifies the **pear** configuration file as a global option. In contrast the **--register-only** option is specific to the **install** command provided by **pear**.

Obviously not all command line interfaces match this scheme. Hence Horde\_Cli\_Modular shouldn't be considered to be a generic utility for all CLI tools. But for all CLI helpers that have such a structure the library should provide a decent skeleton that allows to quickly start adding modules.

Structure
---------

[](#structure)

Horde\_Cli\_Modular provides four classes as main structural elements:

Horde\_Cli\_Modular:The entry point for generating the command line interface.Horde\_Cli\_Modular\_Modules:The handler for the list of modules.Horde\_Cli\_Modular\_ModuleProvide:A module factory.Horde\_Cli\_Modular\_Module:The interface definition for a module.Horde\_Cli\_Modular
-------------------

[](#horde_cli_modular-1)

The Horde\_Cli\_Modular class is the entry point for constructing a modular command line interface. The class provides methods to combine and access the different modules.

### Setup

[](#setup)

This class generates the basic setup and you will only have to provide a few basic parameters to setup the system. This introduction will focus on the central settings and you will need to lookup the API documentation for further details.

The following demonstrates how you could construct the Horde\_Cli\_Modular instance:

```
$modular = new Horde_Cli_Modular(
  array(
    'parser' => array('usage' => '[options] MODULE'),
    'modules' => array('directory' => __DIR__ . '/Module'),
    'provider' => array('prefix' => 'Horde_Something_Module_')
  )
);
```

The **parser** parameter preparse the command line argument parser (usually Horde\_Argv). The snippet above only provides the **usage** setting that will be displayed as the condensed usage instruction when the user requests the help for the CLI script.

The **modules** part defines the **directory** that contains the various modules which are part of the command line interface.

And finally the **provider** setting indicates the common **prefix** that the module classes will have.

The file structure for the hypothetical Horde\_Something package would look like this in order to match the setup presented above:

```
lib/
  Horde/
    Something.php
    Something/
      Module/
        One.php
        Two.php
```

There are two modules: Horde\_Something\_Module\_One in One.php and Horde\_Something\_Module\_Two in Two.php.

### Usage

[](#usage)

After creating the Horde\_Cli\_Modular instance you should create the command line parser and read the arguments the user provided.

```
$parser = $modular->createParser();
list($options, $arguments) = $parser->parseArgs();
```

This is the main action you will need.

Beyond that Horde\_Cli\_Modular will allow you to retrieve the list of modules with:

```
$modules = $modular->getModules();
```

And you can retrieve a module instance using:

```
$module = $modular->getProvider()->getModule('one');
```

Writing modules
---------------

[](#writing-modules)

First and foremost each module can add its own option group with a specific title, description and a set of module specific options (see Horde\_Argv\_OptionGroup for exact details). In addition Horde\_Cli\_Modular allows a module to modify the global usage string and add basic options valid for all modules.

For that to work all modules are required to implement the Horde\_Cli\_Modular\_Module interface:

```
interface Horde_Cli_Modular_Module
{
    public function getUsage();
    public function getBaseOptions();
    public function hasOptionGroup();
    public function getOptionGroupTitle();
    public function getOptionGroupDescription();
    public function getOptionGroupOptions();
}
```

There are two functions that allow to influence the global setup of the command line parser: getUsage() and getBaseOptions(). The first one returns a string that will be added to the generic usage description displayed when the user requests the help screen. The second one returns an array of Horde\_Argv\_Option instances that each define an option valid for all modules.

If the module defines its own option group (that will be displayed as a separate section in the help text for the command) hasOptionGroup() needs to return **true**.

An option group needs a title (returned as a string by getOptionGroupTitle()) and a descriptions (returned as a string by getOptionGroupDescription()). And finally an option group needs a list of options valid for the specific module defining the option group. The corresponding list is returned as an array of Horde\_Argv\_Option instances by the method getOptionGroupOptions().

Examples
--------

[](#examples)

Currently the package Horde\_Kolab\_Cli and the components application both use Horde\_Cli\_Modular. You are referred to these package in order to look at real world examples using the Horde\_Cli\_Modular library.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance75

Regular maintenance activity

Popularity23

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Every ~511 days

Recently: every ~461 days

Total

9

Last Release

56d ago

Major Versions

2.1.0 → 3.0.0alpha12021-02-24

PHP version history (5 changes)2.0.3PHP &gt;=5.3.0,&lt;=6.0.0alpha1

2.0.4PHP &gt;=5.3.0,&lt;=8.0.0alpha1

2.1.0PHP ^5.3 || ^7

3.0.0alpha1PHP ^7

v3.0.0alpha4PHP ^7.4 || ^8

### Community

Maintainers

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

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

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

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

---

Top Contributors

[![yunosh](https://avatars.githubusercontent.com/u/379318?v=4)](https://github.com/yunosh "yunosh (82 commits)")[![ralflang](https://avatars.githubusercontent.com/u/646976?v=4)](https://github.com/ralflang "ralflang (23 commits)")[![wrobel](https://avatars.githubusercontent.com/u/10232?v=4)](https://github.com/wrobel "wrobel (22 commits)")[![slusarz](https://avatars.githubusercontent.com/u/381003?v=4)](https://github.com/slusarz "slusarz (3 commits)")[![mrubinsk](https://avatars.githubusercontent.com/u/66822?v=4)](https://github.com/mrubinsk "mrubinsk (3 commits)")[![thomasjfox](https://avatars.githubusercontent.com/u/1146758?v=4)](https://github.com/thomasjfox "thomasjfox (1 commits)")[![sathieu](https://avatars.githubusercontent.com/u/741106?v=4)](https://github.com/sathieu "sathieu (1 commits)")

### Embed Badge

![Health badge](/badges/horde-cli-modular/health.svg)

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

###  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)
