PHPackages                             sitphp/commands - 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. sitphp/commands

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

sitphp/commands
===============

Simple yet powerful library to run commands from other libraries or to build a command application

v1.0.2(6y ago)181MITPHPPHP &gt;=7.1

Since Jun 5Pushed 6y agoCompare

[ Source](https://github.com/sitphp/commands)[ Packagist](https://packagist.org/packages/sitphp/commands)[ RSS](/packages/sitphp-commands/feed)WikiDiscussions master Synced 1mo ago

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

SitPHP/Commands
===============

[](#sitphpcommands)

[![Build Status](https://camo.githubusercontent.com/c384628a60734baf0904e7cf2d5b263fa23b4b5d1d5a7b72a735ded6466a0d75/68747470733a2f2f7472617669732d63692e6f72672f7369747068702f636f6d6d616e64732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/c384628a60734baf0904e7cf2d5b263fa23b4b5d1d5a7b72a735ded6466a0d75/68747470733a2f2f7472617669732d63692e6f72672f7369747068702f636f6d6d616e64732e7376673f6272616e63683d6d6173746572)

The "sitphp/commands" library can help you to create commands super easily for your application or your library. You can also use it to build your own customized command tool.

See full documentation [here](https://sitphp.com/commands/doc/intro/latest)

[![command showcase](doc/img/command_showcase.gif)](doc/img/command_showcase.gif)

Install
-------

[](#install)

Add the `"sitphp/commands": "1.0.*"` line in the `"require"` section of your composer.json file :

```
{
    "require": {
        "sitphp/commands": "1.0.*"
    }
}
```

Then just run the following composer command to install the library :

```
composer update
```

Creating a command
------------------

[](#creating-a-command)

To build a new command, you should create a new class extending the `\SitPHP\Commands\Command` class in the "Commands" folder of your library or application. This class should implement the `handle` method. Let's create, for example, a "YourCommand" class :

```
namespace App\Commands;

class YourCommand extends \SitPHP\Commands\Command {

    function handle(){
        $this->write('hello');
    }

}
```

Running a command
-----------------

[](#running-a-command)

To run your command, you should use the `command` application located in the `/vendor/bin` folder. To run our previously created "YourCommand" command for example, use the shorthand notation (Namespace:CommandName) :

```
vendor/bin/command App:YourCommand
```

or use the full path (Class name with slashes "/" instead of backslashes "")

```
vendor/bin/command App/Commands/YourCommand
```

Writing text messages
---------------------

[](#writing-text-messages)

To write a message in your terminal, use the `write` or the `writeLn` method. The `writeLn` method will write the message on a new line whereas the `write` method will write the message on the same line.

You can also use the `lineBreak` method to display line breaks. This method can receive an integer argument to specify how many line breaks you wish to write.

```
namespace App\Commands;

class YourCommand extends \SitPHP\Commands\Command {

    function handle(){
        $this->write('Hello,');

        // Single line break
        $this->lineBreak();

        $this->write('I am ');
        $this->write('Alex');

        // Double line break
        $this->lineBreak(2);

        $this->write('I code with PHP');
    }

}
```

[![command write](doc/img/command_write.png)](doc/img/command_write.png)

Arguments and options
---------------------

[](#arguments-and-options)

In order to retrieve options and arguments passed to your command, you must first register them in the `prepare` method of your command class.

- To register an argument, use the `setArgumentInfos` method with name of the argument and its position (0 if it is the first argument, 1 if it is the second argument and so on ...)
- To register an option, use the `setOptionInfos` method with the name of the option. Here, for example, we will register "name" argument and a "color" option.

```
// In your command class ...

function prepare()
{
   // Register "name" argument at position "0"
   $this->setArgumentInfos('name', 0);

   // Register "color" option
   $this->setOptionInfos('color');
}

function handle()
{
   // Retrieve name argument value
   $name = $this->getArgument('name');
   if ($name === null) {
       throw new \Exception('The "name" argument is required');
   }
   $message = 'My name is ' . $name;

   // Retrieve color option value
   $color = $this->getOption('color');
   if ($color !== null) {
       $message .= ' and I like the ' . $color . ' color';
   }

   $this->writeLn($message);
}
```

To send the arguments to your command, just type their value in your terminal. Options should preceded with two hyphens (ex : `--color`). Options can take values like so `--color=red`. If no value is specified, the option value will be `true`.

You could run our previous command typing something like this in the terminal :

```
vendor/bin/command App:YourCommand Alex --color=red
```

This would write : "My name is Alex and I like the red color".

Styling
-------

[](#styling)

Anything written in the terminal can be easily styled using the `` tag.

- You can change the color of your text with the `color` attribute. Available colors are : 'black','white','red','green','yellow','blue','purple','cyan','light\_grey','dark\_grey','light\_red','light\_green','light\_yellow','light\_blue','pink','light\_cyan'.
- You can change the background color of your text with the `background-color` attribute. Available colors are : 'black','white','red','green','yellow','blue','purple','cyan','light\_grey',dark\_grey','light\_red','light\_green','light\_yellow','light\_blue','pink','light\_cyan'.
- You can make your text bold with the `bold` parameter of the `style` attribute
- You can highlight your text with `highlight` parameter of the `style` attribute
- You can underline your text with `underline` parameter of the `style` attribute
- You make your text blink with `blink` parameter of the `style` attribute (some terminals do not support blink)

Here are a few styling examples :

```
// In the "handle" method of your command class ...
$this->writeLn('This will display in blue');
$this->writeLn('This will display highlighted and bold');
$this->writeLn('This will display with a white text in a blue background');
```

[![command style](doc/img/command_style.png)](doc/img/command_style.png)

Tools
-----

[](#tools)

This package comes with some useful tools. It's also easy to build your own if you are using your own command application.

### Bloc tool

[](#bloc-tool)

The bloc tool can display content in a box. A bloc is created with the `bloc` method and displayed with the `display` method. The width of the bloc will automatically adjust to the width of the content.

```
// In the "handle" method of your command class ...
$this->bloc('I am a simple bloc ...')
    ->display();
```

### Progress bar tool

[](#progress-bar-tool)

To create a progress bar, use the `progress` method with an argument to specify the number of steps of your progress bar. Then display it with the `display` method. You can then move the progress line forward with the `progress` method. You might want to "stick" your progress bar with the `placeHere` method so that it does'nt show on a new line on each progress.

```
// In the "handle" method of your command class ...

// Create a 5 steps progress bar
$progress_bar = $this->progressBar(5)
    ->placeHere()
    ->display();

for($i = 1; $i progress();
}
```

[![command progress bar](doc/img/progress_basic.gif)](doc/img/progress_basic.gif)

### The question tool

[](#the-question-tool)

The question tool allows to ask for user input. Use the `question` method to create a new question. This method can take two arguments : the question prompt and an array of autocomplete values.

```
// In the "handle" method of your command class ...
function handle(){
    $genres = ['pop', 'rock', 'hip hop', 'classical'];
    $genre = $this->question('Which music genre do you like ?', $genres)
        ->ask();

    $this->lineBreak();
    $this->writeLn('Your favorite music genre is : '.$genre);
}
```

[![command question](doc/img/question_basic.gif)](doc/img/question_basic.gif)

### The choice tool

[](#the-choice-tool)

The choice tool allows you to ask the user to choose within a predefined set of choices. Use the `choice` method to create a new choice and ask for the user choice using the `ask` method. You might also want to let user quit without answering with the `enableQuit` method. The choice question will be re-displayed until the user has given a correct choice or has quit if possible. When the user chooses to quit, the choice method will return `null`.

The `choice` method can take up to three arguments : an array of choices, the question prompt, and the title.

```
// In the "handle" method of your command class ...
function handle(){
    $choices = ['red', 'blue', 'green'];
    $color_index = $this->choice($choices, 'Which color do you like best ?', 'Colors')
        ->enableQuit()
        ->ask();

    if($color_index !== null){
        $this->lineBreak();
        $this->writeLn('You like the '.$choices[$color_index].' color the best');
    }
}
```

[![command choice](doc/img/choice_basic.gif)](doc/img/choice_basic.gif)

### Section tool

[](#section-tool)

The section is used to update or move content at a predefined position on the screen. You can create a section with the `section` method and place it where you decide with the `placeHere` method. Every content in the section will written at the placed position. Here is an example to illustrate this :

```
// In the "handle" method of your command class ...
$this->writeLn('This goes before');
$section = $this->section()->placeHere();
$this->writeLn('This goes after');

$section->writeLn('This goes in the middle');
sleep(1);
$section->overwriteLn('This goes in the middle');
```

[![command section](doc/img/section_basic.gif)](doc/img/section_basic.gif)

### Table tool

[](#table-tool)

You can use the table tool to display content organized in rows and columns. Use the `table` method to create a table. Then define every table row in an array. You can also insert a table with a `line` item.

```
// In the "handle" method of your command class ...
$this->table([
    ['Animal', 'Classification'],
    'line',
    ['elephant', 'mammal'],
    ['parrot', 'bird']
])->display();
```

[![table command](doc/img/table_basic.png)](doc/img/table_basic.png)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

4

Last Release

2495d ago

### Community

Maintainers

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

---

Top Contributors

[![gealex](https://avatars.githubusercontent.com/u/11295288?v=4)](https://github.com/gealex "gealex (9 commits)")

---

Tags

clicommandcommand-lineconsolephpshellterminalphpcliconsolecommand

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sitphp-commands/health.svg)

```
[![Health](https://phpackages.com/badges/sitphp-commands/health.svg)](https://phpackages.com/packages/sitphp-commands)
```

###  Alternatives

[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M280](/packages/nunomaduro-termwind)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2582.1M11](/packages/nunomaduro-laravel-console-task)[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

9989.0k](/packages/mehrancodes-laravel-harbor)[php-school/learn-you-php

An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.

3192.0k](/packages/php-school-learn-you-php)[alecrabbit/php-cli-snake

Lightweight cli spinner with zero dependencies

29211.3k5](/packages/alecrabbit-php-cli-snake)

PHPackages © 2026

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