PHPackages                             khalyomede/command-builder - 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. khalyomede/command-builder

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

khalyomede/command-builder
==========================

Create executable strings using a fluent API.

0.2.1(4y ago)2173[1 issues](https://github.com/khalyomede/command-builder/issues)MITPHPPHP &gt;=7.4.0

Since Jan 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/khalyomede/command-builder)[ Packagist](https://packagist.org/packages/khalyomede/command-builder)[ RSS](/packages/khalyomede-command-builder/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (4)Used By (0)

command-builder
===============

[](#command-builder)

A PHP class to build executable with using fluent API.

Summary
-------

[](#summary)

- [About](#about)
- [Features](#featues)
- [Installation](#installation)
- [Examples](#examples)
- [Compatibility table](#compatibility-table)
- [Tests](#tests)

About
-----

[](#about)

I need to have a fluent way to call my executable. I did not found any other command builder providing such interface that was updated recently or provide a large test coverage.

Features
--------

[](#features)

- Use a fluent API to construct the string to be executed
- Class-based
- Support arguments, long/short options and flags
- Preserves order of elements
- Does **not** handle executing the command

Installation
------------

[](#installation)

Install the package using Composer:

```
composer require khalyomede/command-builder
```

Examples
--------

[](#examples)

- [1. Create a simple command](#1-create-a-simple-command)
- [2. Add an argument](#2-add-an-argument)
- [3. Add a flag](#3-add-a-flag)
- [4. Add an option](#4-add-an-option)
- [5. Configure the standard](#5-configure-the-standard)
- [6. Get the number of arguments](#6-get-the-number-of-arguments)
- [7. Get the number of flags](#7-get-the-number-of-flags)
- [8. Get the number of options](#8-get-the-number-of-options)
- [9. Check if a flag has been added](#9-check-if-a-flag-has-been-added)
- [10. Check if an option has been added](#10-check-if-an-option-has-been-added)

### 1. Create a simple command

[](#1-create-a-simple-command)

In this example, we will just pass a command name, without arguments/options/flags.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

echo $command; // composer
```

### 2. Add an argument

[](#2-add-an-argument)

In this example, we will add an argument to our command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require");

echo $command; // composer require
```

### 3. Add a flag

[](#3-add-a-flag)

In this example, we will add a "long" flag to the command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->longFlag("ignore-platform-reqs");

echo $command; // composer require --ignore-platform-reqs
```

And this is how to add a "short" flag.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->flag("i");

echo $command; // composer require -i
```

### 4. Add an option

[](#4-add-an-option)

You can add options to your command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->longOption("prefer-install", "source");

echo $command; // composer require --prefer-install=source
```

If your option contains spaces, it will automatically be escaped using double quotes.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->longOption("prefer-install", "auto source");

echo $command; // composer require --prefer-install="auto source"
```

And if your option contains spaces and doubles quotes, they will also be escaped.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->longOption("prefer-install", 'auto "source"');

echo $command; // composer require --prefer-install="auto \"source\""
```

You can also use "short" option.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("require")
  ->option("p", 'source');

echo $command; // composer require -p=source
```

### 5. Configure the standard

[](#5-configure-the-standard)

You can specify the standard used for the option. By default, it is set to "GNU".

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer", "POSIX");

$command->argument("require")
  ->option("p", 'source');

echo $command; // composer require -p source

$command = new Command("composer")

$command->argument("require")
  ->option("p", 'source');

echo $command; // composer require -p=source
```

You can also use constants if you prefer

```
use Khalyomede\CommandBuilder\Command;
use Khalyomede\CommandBuilder\Standard;

$command = new Command("composer", Standard::POSIX);
```

### 6. Get the number of arguments

[](#6-get-the-number-of-arguments)

You can know how many arguments were added to the command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->argument("create-project")
  ->argument("laravel/laravel");

echo $command->argumentCount(); // 2
```

### 7. Get the number of flags

[](#7-get-the-number-of-flags)

You can know the number of flags added to your command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->flag("i")
  ->longFlag("prefer-dist");

echo $command->flagCount(); // 2
```

### 8. Get the number of options

[](#8-get-the-number-of-options)

You can know the number of options added to your command.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->option("a", "source")
  ->longFlag("apcu-autoloader-prefix", "app");

echo $command->optionCount(); // 2
```

### 9. Check if a flag has been added

[](#9-check-if-a-flag-has-been-added)

You can know if a flag has been added already.

```
use Khalyomede\CommandBuilder\Command;

$command = new Command("composer");

$command->longFlag("dev");

var_dump( $command->hasFlag("d", "dev") ); // bool(true)
var_dump( $command->hasFlag("o", "optimize-autoloader") ); // bool(false)
```

### 10. Check if an option has been added

[](#10-check-if-an-option-has-been-added)

You can know if an option has been added or not.

```
use Khalyomede\CommandBuilder\Command;
use Khalyomede\CommandBuilder\Style;

$command = new Command("composer");

$command->longOption("prefer-install", "source");

var_dump( $command->hasOption("p", "prefer-install") ); // bool(true)
var_dump( $command->hasOption("i", "ignore-platform-req") ); // bool(false)
```

Compatibility table
-------------------

[](#compatibility-table)

This is the compatibility for this version only. To check the compatibility with other version of this package, please browse the version of your choice.

PHP VersionCompatibility8.1.\*✔️8.0.\*✔️7.4.\*✔️Tests
-----

[](#tests)

```
composer run test
composer run mutate
composer run analyse
composer run lint
composer run install-security-checker
composer run check-security
composer run check-updates
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~1 days

Total

3

Last Release

1625d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (20 commits)")

---

Tags

buildercommandexecutablefluent-apiexecutablebuilderfluentcommand

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/khalyomede-command-builder/health.svg)

```
[![Health](https://phpackages.com/badges/khalyomede-command-builder/health.svg)](https://phpackages.com/packages/khalyomede-command-builder)
```

###  Alternatives

[league/climate

PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.

1.9k14.7M301](/packages/league-climate)[league/tactician

A small, flexible command bus. Handy for building service layers.

86516.0M138](/packages/league-tactician)[nategood/commando

PHP CLI Commando Style

8123.4M40](/packages/nategood-commando)[helhum/typo3-console

A reliable and powerful command line interface for TYPO3 CMS

2959.5M256](/packages/helhum-typo3-console)[adhocore/cli

Command line interface library for PHP

3511.4M59](/packages/adhocore-cli)[jmose/command-scheduler-bundle

This Symfony bundle will allow you to schedule all your commands just like UNIX crontab

3361.4M1](/packages/jmose-command-scheduler-bundle)

PHPackages © 2026

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