PHPackages                             juanchosl/terminal - 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. juanchosl/terminal

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

juanchosl/terminal
==================

Little methods collection in order to create console commands

142PHP

Since Jul 29Pushed 9mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Terminal
========

[](#terminal)

Description
-----------

[](#description)

Little methods collection in order to create console commands

Install
-------

[](#install)

```
composer require juanchosl/terminal
```

How to use
----------

[](#how-to-use)

### Create a Command, extending the Command Library class

[](#create-a-command-extending-the-command-library-class)

Commans is a simple implementation of use cases, we need to define the name, arguments and code to execute

#### Name

[](#name)

The name of the command, first argument to indicate the action to execute

```
    public function getName(): string
    {
        return "copy";
    }
```

#### Configuration

[](#configuration)

Declare the arguments, his name, if it is required and the quantity of values, void if don't have, simgle or multiple

```
    protected function configure(): void
    {
        $this->addArgument('origin', InputArgument::REQUIRED, InputOption::SINGLE);
        $this->addArgument('destiny', InputArgument::REQUIRED, InputOption::MULTIPLE);
        $this->addArgument('copies', InputArgument::OPTIONAL, InputOption::SINGLE);
        $this->addArgument('clean', InputArgument::OPTIONAL, InputOption::VOID);
    }
```

#### Execution

[](#execution)

The code to execute, as an use case, returning an integer as result code, 0 for no errors

```
    protected function execute(InputInterface $input): int
    {
        $this->write($input->getArgument('origin'));
        $this->write($input->getArgument('destiny'));
        if ($input->hasArgument('copies')) {
            $this->write($input->getArgument('copies'));
        }
        if ($input->hasArgument('clean')) {
            $this->write($input->getArgument('clean'));
        }
        return 0;
    }
```

### Create an App call

[](#create-an-app-call)

#### Direct command call

[](#direct-command-call)

We can execute directly the command created previously. If we do not pass parameters to run method, the library read the \_SERVER global in order to retrieve the parameters passed to php script used as entrypoint

```
$command = new CopyCommand();
$command->run();
```

Then, call the script from the console, passing the command name and the parameters desireds

```
./entrypoint --origin=values.txt --destiny values.csv values.xml --copies 1 --clean
```

If your system does not support call scripts with parameters, insert into your script the desired values as

- array of strings

```
$command = new CopyCommand();
$command->run(['--required_single', 'value', '--required_void', '--required_multi', 'a', 'b', 'c']);
```

- InputInterface element

```
$input = new Input;
$input->addArgument('required_single', 'value');
$input->addArgument('required_void', null);
$input->addArgument('required_multi', ['a', 'b', 'c']);

$command = new CopyCommand();
$command->run($input);
```

#### Create an App with multiple commands

[](#create-an-app-with-multiple-commands)

In our entrypoint script, we can declare some commands in order to use it with multiple purposes, using the name of the desired command as first parameter. Create a file and put the use case commands

```
use JuanchoSL\Terminal\Console;
use App\CopyCommand;
use App\DeleteCommand;

$app = new Console;
$app->add(new CopyCommand);
$app->add(new DeleteCommand);
$app->run();
```

Then, call the script from the console, passing the command name and the parameters desireds

```
./entrypoint copy --origin=values.txt --destiny values.csv values.xml --copies 1 --clean
```

#### Parameters format

[](#parameters-format)

The parameter name needs to start with --, the can assign values from:

- concat with an equals sign (--name=value)
- put the value after parameter (--name value)
- if is a void parameter that don't need value, just write the parameter name (--void\_parameter)
- if is a multiple values parameter, use the name all times that you need pass a value or write the name and value multiple times as a single value
    - --multiple=value1 --multiple=value2
    - --multiple value1 --multiple value2
    - --multiple value1 value2

Help
----

[](#help)

### Available commands

[](#available-commands)

If you don't know the available commands configured into an entrypoint console app, write help for retrieve a list

```
$ ./bin/command.php help
Available commands:
- usecase
```

### Available arguments

[](#available-arguments)

If you don't know the available arguments configured into a command console app, write help after command name for retrieve a list

```
$ ./bin/command.php usecase help
Available arguments for usecase:
- required_single: required,single
- required_multi: required,multiple
- required_void: optional,void
```

### Personalize help

[](#personalize-help)

You can personalize your command help system overriding the protected function help, returning an integer, 0 for no errors

```
    protected function help(): int
    {
        print_r($this->arguments);
        return 0;
    }
```

Debug
-----

[](#debug)

The library implements the LoggerAwaitInterface, in order to indicate a PSR3 Logger for save errors or debug info. The loggers are used by commands, but if you have multiple commands from a Console App, can pass an unique log to Console class before insert Commands and the logger will be inserted into any Command used

```
use JuanchoSL\Terminal\Console;
use App\CopyCommand;
use App\DeleteCommand;
use JuanchoSL\Logger\Composers\TextComposer;
use JuanchoSL\Logger\Logger;
use JuanchoSL\Logger\Repositories\FileRepository;

$file_logger = new Logger((new FileRepository(realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'errors.log'))->setComposer(new TextComposer));

$app = new Console();
$app->setLogger($file_logger);
$app->setDebug(false);
$app->add(new CopyCommand);
$app->add(new DeleteCommand);
$app->run();
```

If you enable the debug mode, all run actions will be traced into log

```
[2024-12-20T20:09:54+00:00] [debug] Command: './entrypoint delete --folder=../files/*.old'
{
   "arguments": [
       "delete",
       "--folder=..\/files\/*.old"
   ],
   "input": {
       "folder": "..\/files\/*.old"
   },
   "result": 0,
   "time": 0,
   "memory": 1184304
}
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance40

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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/bd6d3dea7eb469817524c42a80683e95793ed4800a6794366503355af046a726?d=identicon)[Juanchosl](/maintainers/Juanchosl)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (25 commits)")

### Embed Badge

![Health badge](/badges/juanchosl-terminal/health.svg)

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

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-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)[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)
