PHPackages                             weew/console - 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. weew/console

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

weew/console
============

Console application skeleton.

v1.17.1(9y ago)01893MITPHP

Since Apr 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/weew/console)[ Packagist](https://packagist.org/packages/weew/console)[ RSS](/packages/weew-console/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (10)Versions (28)Used By (3)

Console application
===================

[](#console-application)

[![Build Status](https://camo.githubusercontent.com/cf47947c849b5ffdb5cb81e80301af95c8063d983861d92ed123e3fe224ff2e3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f636f6e736f6c652e737667)](https://travis-ci.org/weew/console)[![Code Quality](https://camo.githubusercontent.com/19e51c038d6589a5becd9028f23a730bea4b65cee864686f6631b6ee9bc7238a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f636f6e736f6c652e737667)](https://scrutinizer-ci.com/g/weew/console)[![Test Coverage](https://camo.githubusercontent.com/36990b9414c958e5039e37c0ee0e6e525762280fad84dd9957f3cd99d7bf0920/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f636f6e736f6c652e737667)](https://coveralls.io/github/weew/console)[![Version](https://camo.githubusercontent.com/82863e3f6b1abbb1cbd482a07fa5d135855024f06f5443d6b47c3ff0d5c2ec0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f636f6e736f6c652e737667)](https://packagist.org/packages/weew/console)[![Licence](https://camo.githubusercontent.com/38d5d1a5f9b5b715ae9143c0448c9c3c8b4f4fa217dcf5ddf36e316cbe188d80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f636f6e736f6c652e737667)](https://packagist.org/packages/weew/console)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Introduction](#introduction)
- [Console](#console)
- [Input](#input)
- [Output](#output)
- [Widgets](#widgets)
    - [TableWidget](#tablewidget)
- [Helpers](#helpers)
    - [PromptHelper](#prompthelper)
- [Related projects](#related-projects)

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

[](#installation)

`composer require weew/console`

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

[](#introduction)

[![Screenshot](screenshot.png?raw=true)](screenshot.png?raw=true)

This package provides a convenient skeleton for console application. Optically, heavily inspired by the symfony console it has it similarities and differences. Describing commands, parsing console arguments, styling and colorization of output, question helpers etc., all this is included inside this package. In [related projects](#related-projects) you'll find a list of used components that you might also use separately from this package.

Note: this package has not been tested on windows. Windows contributions are highly appreciated.

Console
-------

[](#console)

To start building your console app, you need to instantiated a new console first.

```
$console = new Console();
```

Commands
--------

[](#commands)

Commands are the pieces of logic that you might plug and play into your console application. A command can by anything. There is no interface contract that you must fulfill. This design choice was made because of the dependency injection support for the [weew/console-container-aware](https://github.com/weew/console-formatter) package.

Your command must have the `setup` and `run` method. For further information about configuration of commands refer to the [weew/console-arguments](https://github.com/weew/console-arguments) package.

```
class SampleCommand {
    public function setup(ICommand $command) {
        // describe command

        $command->setName('colors')
            ->setDescription('Shows a list of colors');

        $command->argument(ArgumentType::SINGLE, 'favorite_color');
        $command->argument(ArgumentType::SINGLE_OPTIONAL, '--only-light');
        $command->argument(ArgumentType::SINGLE_OPTIONAL, '--only-dark');
    }

    public function run(IInput $input, IOutput $output, IConsole $console) {
        // do your thang

        if ( ! $input->hasOption('--only-dark')) {
            $output->writeLine('red');
        }

        if ( ! $input->hasOption('--only-light')) {
            $output->writeLine('blue');
        }

        if ($input->hasArgument('favorite_color')) {
            $favoriteColor = $input->getArgument('favorite_color');
            $output->writeLine("The best of all colors is $favoriteColor");
        }
    }
}
```

All the important functionality is available trough instances of `IInput` and `IOutput`. There are many more things you can do, just take a look at it. All you have to do now is to register your command on the console.

```
$console->addCommand(SampleCommand::class);

// or

$console->addCommand(new SampleCommand());
```

Running your command is as easy as pie.

```
$console->parseString('colors red --only-dark');

// or

$console->parseArgs(['colors', 'red', '--only-dark'];

// or

$console->parseArgv(['./file_name', 'colors', 'red', '--only-dark']);
```

You can prevent a command from executing in parallel setting the appropriate flag.

```
$command->setParallel(false);
```

Input
-----

[](#input)

Input contains all the information about the received arguments and offers some apis for interaction with the user.

This is how you can retrieve the current command:

```
$input->getCommand();
```

You can access arguments and options that were matched for the command:

```
$input->getArgument('argument');
$input->getOption('--option');
```

You can prompt user for input using this methods:

```
$input->readline();
$input->readChar();
```

Output
------

[](#output)

Output is used to print information to the terminal. It uses the [weew/console-formatter](https://github.com/weew/console-formatter) for styling and formatting of the text.

```
$output->writeLine('key:  value');
$output->write('some text);
```

Widgets
-------

[](#widgets)

Widgets are small and reusable classes that serve as a kind of ui elements.

### TableWidget

[](#tablewidget)

This widget allows you to easily print simple tables.

```
$table = new TableWidget($input, $output);
$table
    ->setTitle('Table title')
    ->addRow('task1', 'x')
    ->addSection('Done tasks')
    ->addRow('task2', '✓');

$table->render();
```

Helpers
-------

[](#helpers)

There are several helpers that you might use for interaction with the user.

### PromptHelper

[](#prompthelper)

This helper allows you to prompt user for different kinds of input.

```
$prompt = new PromptHelper($input, $output);
$response = $prompt->ask('Are you ready?');
$response = $prompt->prompt('What is your name');
```

Related projects
----------------

[](#related-projects)

- [Console formatter](https://github.com/weew/console-formatter) Used for styling of output
- [Console arguments](https://github.com/weew/console-arguments) Used for parsing of arguments
- [Container aware console](https://github.com/weew/console-container-aware) Container aware version of this package

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity73

Established project with proven stability

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

Recently: every ~2 days

Total

27

Last Release

3400d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

### Embed Badge

![Health badge](/badges/weew-console/health.svg)

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

###  Alternatives

[illuminate/console

The Illuminate Console package.

13046.0M6.3k](/packages/illuminate-console)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15311.8M36](/packages/magento-magento2-functional-testing-framework)

PHPackages © 2026

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