PHPackages                             kentaro-a/phpcommander - 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. kentaro-a/phpcommander

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

kentaro-a/phpcommander
======================

PHP Command line interface. Easy to handle flags and options.

v1.1.0(5y ago)09MITPHPPHP &gt;=7.1

Since Sep 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kentaro-a/PHPCommander)[ Packagist](https://packagist.org/packages/kentaro-a/phpcommander)[ Docs](https://github.com/kentaro-a/PHPCommander)[ RSS](/packages/kentaro-a-phpcommander/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

PHPCommander
============

[](#phpcommander)

Easy to handle flags and options which passed through by $argv. Flags and options have to be start with "-" or "--". If you've already have any classes and you'd like to make something like CLI batches with it, PHPCommander makes it easy.

Requirements
============

[](#requirements)

- php &gt;= 7.1

Install
=======

[](#install)

```
$ composer require kentaro-a/phpcommander

```

How To Use
==========

[](#how-to-use)

### Make Flags for command

[](#make-flags-for-command)

Use new Flg(string $flg, bool $must=false, string $help="", array $validators=\[\]) to make Flag. you can make custom validator class like preset validator ValidatorNotEmptyString.

paramdesc$flgrequire, this must start with - or --$mustoptional default=false, if true check for being passed flg in cli args.$helpoptional default="", help text to be shown.$validatorsoptional default=\[\], an array of sub classes of Validator to validate flg.```
$flg1 = new Flg("--param", true, "my parameter", [new ValidatorNotEmptyString("Flg --param doesn't permit blank.")]);

```

### You can make Procedure which implements [ProcedureInterface](https://github.com/kentaro-a/PHPCommander/blob/master/src/ProcedureInterface.php).

[](#you-can-make-procedure-which-implements-procedureinterface)

```
class EchoProcedure implements ProcedureInterface {
	public function __invoke(array $flgs=[]) {
		// Whatever you want.
		echo $flgs["param"] ."\n";
	}
}

```

### Make Command

[](#make-command)

After making Procedure you can set it into Command. Using new Command(string $command\_name, ProcedureInterface $procedure, Flgs $flgs=null, string $description="").

paramdesc$command\_namerequire, this must not start with - or --$procedurerequire, procedure to be called when command passed.$flgsoptional default=null, Flgs class contains an array of Flg classes.$descriptionoptional default="", description text to be shown in help.```
$command_echo = new Command(
	"echo",
	new EchoProcedure(),
	new Flgs([$flg1]),
	"Simple echo parameter",
);

```

### Add Commands into Commander and invoke registered command.

[](#add-commands-into-commander-and-invoke-registered-command)

Commander::invoke obtains command name and options from $argv then invokes relevant Procedure::\_\_invoke().

```
// Make instance.
$cli = new Commander($argv, [$command_echo]);

// you can also add other command by pushing into $commands or using add method like $cli->addCommand($command).

// Invoke procedure related on command name passed by $argv
$ret = $cli->invoke();

```

Show help.
==========

[](#show-help)

You can show registered command list without any parameters.

```
$ php batch.php

```

You can also pass the reserved flg after command\_name like -h or --help to show help.

```
$ php batch.php echo -h(--help)

```

Detail
======

[](#detail)

See [examples](https://github.com/kentaro-a/PHPCommander/tree/master/examples).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

2058d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

v1.0.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dc3823e71ba9cc0f53bf8976b15ea57a29bf2b56efd3a83ce75f2637d9a558f?d=identicon)[kentaro-a](/maintainers/kentaro-a)

---

Top Contributors

[![kentaro-a](https://avatars.githubusercontent.com/u/11267597?v=4)](https://github.com/kentaro-a "kentaro-a (7 commits)")

---

Tags

php-cliphp commandphpcommanderphp commandline interfacephp flagphp argv

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kentaro-a-phpcommander/health.svg)

```
[![Health](https://phpackages.com/badges/kentaro-a-phpcommander/health.svg)](https://phpackages.com/packages/kentaro-a-phpcommander)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[adhocore/cli

Command line interface library for PHP

3501.2M50](/packages/adhocore-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/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)

PHPackages © 2026

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