PHPackages                             krisanalfa/konsole - 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. krisanalfa/konsole

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

krisanalfa/konsole
==================

Minimum Console Application with PHP.

1.0.0(10y ago)0201MITPHP

Since Feb 19Pushed 9y agoCompare

[ Source](https://github.com/krisanalfa/konsole)[ Packagist](https://packagist.org/packages/krisanalfa/konsole)[ RSS](/packages/krisanalfa-konsole/feed)WikiDiscussions master Synced 4w ago

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

Konsole
=======

[](#konsole)

[![Latest Stable Version](https://camo.githubusercontent.com/9a217c8c6fea38b78fb48645c9197fd87f72f2282117e1d818e23a11f9307a28/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f76657273696f6e)](https://packagist.org/packages/krisanalfa/konsole)[![Latest Unstable Version](https://camo.githubusercontent.com/341a2c411102c01292eb736a3ac75ebaac6f3148a90275ec987318df80974142/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f762f756e737461626c65)](https://packagist.org/packages/krisanalfa/konsole)[![Total Downloads](https://camo.githubusercontent.com/f28b78f4e28255332c2ccb0f247bd6b8ff677e73f491f50c5eb31e87e087d6e4/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f646f776e6c6f616473)](https://packagist.org/packages/krisanalfa/konsole)[![License](https://camo.githubusercontent.com/c2f01de178d837aac480a1acc4f896035d0af5d99cdcf9c17e85acbc5574fecc/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f6c6963656e7365)](https://packagist.org/packages/krisanalfa/konsole)[![Monthly Downloads](https://camo.githubusercontent.com/2b89566d63d3824ff8e3c89e165b633d8e86a983c0b73f6ab5e49bab3bcfd7da/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f642f6d6f6e74686c79)](https://packagist.org/packages/krisanalfa/konsole)[![Daily Downloads](https://camo.githubusercontent.com/a0c2cb31bdefffe8281c0056be36068d8a6c28f4d8f4ae8746aa72064f753122/68747470733a2f2f706f7365722e707567782e6f72672f6b726973616e616c66612f6b6f6e736f6c652f642f6461696c79)](https://packagist.org/packages/krisanalfa/konsole)

- [Introduction](#introduction)
- [Installing](#installing)
- [Writing Commands](#writing-commands)
    - [Command Structure](#command-structure)
- [Command I/O](#command-io)
    - [Defining Input Expectations](#defining-input-expectations)
    - [Retrieving Input](#retrieving-input)
    - [Prompting For Input](#prompting-for-input)
    - [Writing Output](#writing-output)
- [Registering Commands](#registering-commands)
- [Calling Commands from Other Commands](#calling-commands-from-other-commands)
- [Logging](#logging)

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

[](#introduction)

Konsole is a minimum console application built on Laravel Console components. To view a list of all available Konsole commands, you may use the `list` command:

```
php konsole list
```

Every command also includes a "help" screen which displays and describes the command's available arguments and options. To view a help screen, simply precede the name of the command with `help`:

```
php konsole help generate
```

Installing
----------

[](#installing)

Installing Konsole can be done simply via `composer` command:

```
composer create-project krisanalfa/konsole my-console-application
cd my-console-application
php konsole --version
```

Writing Commands
----------------

[](#writing-commands)

In addition to the commands provided with Konsole, you may also build your own custom commands for working with your application. You may store your custom commands in the `src/Konsole/Commands` directory; however, you are free to choose your own storage location as long as your commands can be autoloaded based on your `composer.json` settings.

To create a new command, you may use the `generate` Konsole command, which will generate a command stub to help you get started:

```
php konsole generate SendEmails
```

The command above would generate a class at `src/Konsole/Commands/SendEmails.php`. When creating the command, the `--command` or `-C` option may be used to assign the terminal command name:

```
php konsole make:console SendEmails --command=emails:send
```

To add a description in your newly generated command, you can supply `--description` or `-D` option:

```
php konsole make:console SendEmails --command=emails:send --description='Send email to a given user id.'
```

If you want to force generate the command, you may supply `--force` or `-F` option:

```
php konsole make:console SendEmails --command=emails:send --force
```

### Command Structure

[](#command-structure)

Once your command is generated, you should fill out the `signature` and `description` properties of the class, which will be used when displaying your command on the `list` screen.

The `handle` method will be called when your command is executed. You may place any command logic in this method. Let's take a look at an example command.

Note that we are able to inject any dependencies we need into the command's constructor. The Laravel service container will automatically inject all dependencies type-hinted in the constructor. For greater code reusability, it is good practice to keep your console commands light and let them defer to application services to accomplish their tasks.

```
namespace Konsole\Commands;

use Konsole\Command;

class SendEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = '';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
    }
}
```

Command I/O
-----------

[](#command-io)

### Defining Input Expectations

[](#defining-input-expectations)

When writing console commands, it is common to gather input from the user through arguments or options. Konsole makes it very convenient to define the input you expect from the user using the `signature` property on your commands. The `signature` property allows you to define the name, arguments, and options for the command in a single, expressive, route-like syntax.

All user supplied arguments and options are wrapped in curly braces. In the following example, the command defines one **required** argument: `user`:

```
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user}';
```

You may also make arguments optional and define default values for optional arguments:

```
// Optional argument...
protected $signature = 'email:send {user?}'

// Optional argument with default value...
protected $signature = 'email:send {user=foo}'
```

Options, like arguments, are also a form of user input. However, they are prefixed by two hyphens (`--`) when they are specified on the command line. We can define options in the signature like so:

```
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user} {--pretending}';
```

In this example, the `--pretending` switch may be specified when calling the Konsole command. If the `--pretending` switch is passed, the value of the option will be `true`. Otherwise, the value will be `false`:

```
php konsole email:send 1 --pretending
```

You may also specify that the option should be assigned a value by the user by suffixing the option name with a `=` sign, indicating that a value should be provided:

```
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user} {--pretending=}';
```

In this example, the user may pass a value for the option like so:

```
php konsole email:send 1 --pretending=default
```

You may also assign default values to options:

```
protected $signature = 'email:send {user} {--pretending=default}';
```

To assign a shortcut when defining an option, you may specify it before the option name and use a | delimiter to separate the shortcut from the full option name:

```
protected $signature = 'email:send {user} {--P|pretending}';
```

If you would like to define arguments or options to expect array inputs, you may use the `*` character:

```
protected $signature = 'email:send {user*}';
```

Or:

```
protected $signature = 'email:send {user} {--id=*}';
```

#### Input Descriptions

[](#input-descriptions)

You may assign descriptions to input arguments and options by separating the parameter from the description using a colon:

```
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send
                        {user : The ID of the user}
                        {--pretending= : Whether the job should be prentended}';
```

### Retrieving Input

[](#retrieving-input)

While your command is executing, you will obviously need to access the values for the arguments and options accepted by your command. To do so, you may use the `argument` and `option` methods:

```
/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $userId = $this->argument('user');

    //
}
```

If you need to retrieve all of the arguments as an `array`, call `argument` with no parameters:

```
$arguments = $this->argument();
```

Options may be retrieved just as easily as arguments using the `option` method. Like the `argument` method, you may call `option` without any parameters in order to retrieve all of the options as an `array`:

```
// Retrieve a specific option...
$isPretending = ($this->option('pretending') !== null);

// Retrieve all options...
$options = $this->option();
```

If the argument or option does not exist, `null` will be returned.

### Prompting For Input

[](#prompting-for-input)

In addition to displaying output, you may also ask the user to provide input during the execution of your command. The `ask` method will prompt the user with the given question, accept their input, and then return the user's input back to your command:

```
/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $name = $this->ask('What is your name?');
}
```

The `secret` method is similar to `ask`, but the user's input will not be visible to them as they type in the console. This method is useful when asking for sensitive information such as a password:

```
$password = $this->secret('What is the password?');
```

#### Asking For Confirmation

[](#asking-for-confirmation)

If you need to ask the user for a simple confirmation, you may use the `confirm` method. By default, this method will return `false`. However, if the user enters `y` in response to the prompt, the method will return `true`.

```
// The default answer is 'no|N'
if ($this->confirm('Do you wish to continue? [y|N]')) {
    // Do something if user answer 'yes|y'
}
```

#### Giving The User A Choice

[](#giving-the-user-a-choice)

The `anticipate` method can be used to provide autocompletion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:

```
$name = $this->anticipate('What is your name?', ['Alfa', 'Fitria']);
```

If you need to give the user a predefined set of choices, you may use the `choice` method. The user chooses the index of the answer, but the value of the answer will be returned to you. You may set the default value to be returned if nothing is chosen:

```
$name = $this->choice('What is your name?', ['Alfa', 'Fitria'], $default);
```

### Writing Output

[](#writing-output)

To send output to the console, use the `line`, `info`, `comment`, `question`, `warn` and `error` methods. Each of these methods will use the appropriate ANSI colors for their purpose.

To display an information message to the user, use the `info` method. Typically, this will display in the console as green text:

```
/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $this->info('Display this on the screen');
}
```

To display an warning message, use the `warn` method. Warning message text is typically displayed in orange:

```
$this->warn('Something went wrong!');
```

To display an error message, use the `error` method. Error message text is typically displayed in red:

```
$this->error('Something went wrong!');
```

If you want to display plain console output, use the `line` method. The `line` method does not receive any unique coloration:

```
$this->line('Display this on the screen');
```

If you want to suggest user to do something, you can use the `suggest` method:

```
$this->suggest('Better you pick Sven, because you have Magnus on your side.');
```

#### Table Layouts

[](#table-layouts)

The `table` method makes it easy to correctly format multiple rows / columns of data. Just pass in the headers and rows to the method. The width and height will be dynamically calculated based on the given data:

```
$headers = ['Name', 'Email'];

$this->table($headers, $collection->toArray());
```

#### Progress Bars

[](#progress-bars)

For long running tasks, it could be helpful to show a progress indicator. Using the output object, we can start, advance and stop the Progress Bar. You have to define the number of steps when you start the progress, then advance the Progress Bar after each step:

```
$bar = $this->output->createProgressBar(count($users));

foreach ($users as $user) {
    $this->performTask($user);

    $bar->advance();
}

$bar->finish();
```

For more advanced options, check out the [Symfony Progress Bar component documentation](http://symfony.com/doc/2.7/components/console/helpers/progressbar.html).

Registering Commands
--------------------

[](#registering-commands)

Once your command is finished, you need to register it with Konsole so it will be available for use. This done within the `config/app.php`. You may add your commands in `commands` section:

```
'commands' => [
    'Konsole\Commands\SendEmails',
    'Konsole\Commands\GenerateCommand',
],
```

In some cases you may want to register your command via Service Provider. This is done within the `bootstrap/app.php` file. Within this file, you may register your own command via `registerCommand` method:

```
$konsole->registerCommand('Konsole\Commands\SendEmails');
```

Or if you wish to add more than one commands, you may pass the argument of `registerCommand` method in array:

```
$konsole->registerCommand([
    'Konsole\Commands\FooBarBaz',
    'Konsole\Commands\SendEmails',
    'Konsole\Commands\AnotherCommand',
]);
```

Calling Commands From Other Commands
------------------------------------

[](#calling-commands-from-other-commands)

Sometimes you may wish to call other commands from an existing Konsole command. You may do so using the `call` method. This `call` method accepts the command name and an array of command parameters:

```
/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $this->call('email:send', [
        'user' => 1, '--pretending' => 'default'
    ]);

    //
}
```

If you would like to call another console command and suppress all of its output, you may use the `callSilent` method. The `callSilent` method has the same signature as the `call` method:

```
$this->callSilent('email:send', [
    'user' => 1, '--pretending' => 'default'
]);
```

Logging
-------

[](#logging)

The Konsole logging facilities provide a simple layer on top of the powerful [Monolog](http://github.com/seldaek/monolog) library. By default, Konsole is configured to create daily log files for your application which are stored in the `var/log` directory. You may write information to the logs using the `$konsole->make('log')` object. The Konsole logger provides the eight logging levels defined in [RFC 5424](http://tools.ietf.org/html/rfc5424): **emergency**, **alert**, **critical**, **error**, **warning**, **notice**, **info** and **debug**.

```
$konsole->log->emergency($message);
$konsole->log->alert($message);
$konsole->log->critical($message);
$konsole->log->message($message);
$konsole->log->warning($message);
$konsole->log->notice($message);
$konsole->log->info($message);
$konsole->log->debug($message);
```

#### Contextual Information

[](#contextual-information)

An array of contextual data may also be passed to the log methods. This contextual data will be formatted and displayed with the log message:

```
$konsole->make('log')->info('User failed to login.', ['id' => $user->id]);
```

#### Accessing The Underlying Monolog Instance

[](#accessing-the-underlying-monolog-instance)

Monolog has a variety of additional handlers you may use for logging. If needed, you may access the underlying Monolog instance being used by Konsole:

```
$monolog = $konsole->make('log');
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~0 days

Total

6

Last Release

3782d ago

Major Versions

0.0.5 → 1.0.02016-02-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/5585ab7e83e92b16ebfde64d7d90ff330721bcb1fbfa193fb0ffe149a4b3a7d1?d=identicon)[krisanalfa](/maintainers/krisanalfa)

---

Top Contributors

[![krisanalfa](https://avatars.githubusercontent.com/u/3734729?v=4)](https://github.com/krisanalfa "krisanalfa (5 commits)")[![MASNathan](https://avatars.githubusercontent.com/u/2139464?v=4)](https://github.com/MASNathan "MASNathan (1 commits)")

---

Tags

phpconsoleapplicationprojectminimum

### Embed Badge

![Health badge](/badges/krisanalfa-konsole/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.7k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k2.1M163](/packages/laravel-ai)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77018.2M122](/packages/laravel-mcp)[propaganistas/laravel-disposable-email

Disposable email validator

6012.9M7](/packages/propaganistas-laravel-disposable-email)

PHPackages © 2026

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