<commit_before># Silly

Silly CLI micro-framework based on Symfony Console.

[![Build Status](https://img.shields.io/travis/mnapoli/silly.svg?style=flat-square)](https://travis-ci.org/mnapoli/silly)
[![Coverage Status](https://img.shields.io/coveralls/mnapoli/silly/master.svg?style=flat-square)](https://coveralls.io/r/mnapoli/silly?branch=master)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/mnapoli/silly.svg?style=flat-square)](https://scrutinizer-ci.com/g/mnapoli/silly/?branch=master)

## Installation

```bash
$ composer require mnapoli/silly
```

## Usage

To define a command:

```php
$app = new Silly\Application();

$app->command('greet name? --yell', function ($name, $yell, OutputInterface $output) {
    if ($name) {
        $text = 'Hello, '.$name;
    } else {
        $text = 'Hello';
    }

    if ($yell) {
        $text = strtoupper($text);
    }

    $output->writeln($text);
});

$app->run();
```

`Silly\Application` extends `Symfony\Console\Application` and can be used wherever Symfony's Application can.

### Command definition

Commands are defined using a string expression. The expression must start with the command name, optionally using `:` as a namespace separator, for example:

- `greet`
- `demo:greet`

#### Arguments

A command can take arguments:

| Description                            | Example       |
|----------------------------------------|---------------|
| Required argument                      | `greet name`  |
| Optional argument                      | `greet name?` |
| Array argument with 0-n values         | `greet name*` |
| Array argument with at least one value | `greet name+` |

#### Options

A command can take options:

| Description                    | Example                 |
|--------------------------------|-------------------------|
| Simple flag                    | `greet --yell`          |
| Option with an mandatory value | `greet --iterations=`   |
| Option with an optional value  | `greet --iterations[=]` |
| Option that can be used multiple times <br> (the value would be an array) | `greet [--iterations=]*` |
| Option with a shortcut         | `greet -y|--yell`       |

Options are always **optional** (duh). If an option is required, then it should be an argument.

### Command callable

A command can be [any PHP callable](http://php.net/manual/en/language.types.callable.php):

```php
// Closure
$app->command('foo', function () {
    // ...
});

// An object implementing __invoke()
$app->command('foo', new InvokableObject());

// An object method
$app->command('foo', [$object, 'method']);

// A static class method
$app->command('foo', ['MyClass', 'method']);

// A function
$app->command('foo', ['someFunction']);
```

The callable can take as parameters the arguments and options defined in the expression:

```php
$app->command('greet name --yell', function ($name, $yell) {
    // ...
});
```

When running `bin/console greet john --yell`:

- `$name` will be `'john'`
- `$yell` will be `true`

You can also ask for the `$input` and `$output` parameters to get the traditional Symfony `InputInterface` and `OutputInterface` objects:

```php
$app->command(
    'greet name --yell',
    function (InputInterface $input, OutputInterface $output) {
        $name = $input->getArgument('name');
        $yell = $input->getOption('yell');

        // ...
    }
);
```

Finally, you can mix all that. Parameters are detected by their name.

```php
$app->command(
    'greet name --yell',
    function ($name, InputInterface $input, OutputInterface $output) {
        // ...
    }
);
```

## Learn more

Silly is just an implementation over the Symfony Console. Read [its documentation](http://symfony.com/doc/current/components/console/introduction.html) to learn everything you can do with it.

## Contributing

See the [CONTRIBUTING](CONTRIBUTING.md) file.
<commit_msg>Documentation<commit_after># Silly

Silly CLI micro-framework based on Symfony Console.

[![Build Status](https://img.shields.io/travis/mnapoli/silly.svg?style=flat-square)](https://travis-ci.org/mnapoli/silly)
[![Coverage Status](https://img.shields.io/coveralls/mnapoli/silly/master.svg?style=flat-square)](https://coveralls.io/r/mnapoli/silly?branch=master)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/mnapoli/silly.svg?style=flat-square)](https://scrutinizer-ci.com/g/mnapoli/silly/?branch=master)

## Installation

```bash
$ composer require mnapoli/silly
```

## Usage

To define a command:

```php
$app = new Silly\Application();

$app->command('greet name? --yell', function ($name, $yell, OutputInterface $output) {
    if ($name) {
        $text = 'Hello, '.$name;
    } else {
        $text = 'Hello';
    }

    if ($yell) {
        $text = strtoupper($text);
    }

    $output->writeln($text);
});

$app->run();
```

`Silly\Application` extends `Symfony\Console\Application` and can be used wherever Symfony's Application can.

### Command definition

Commands are defined using a string expression. The expression must start with the command name, optionally using `:` as a namespace separator, for example:

- `greet`
- `demo:greet`

#### Arguments

A command can take arguments:

| Description                            | Example       |
|----------------------------------------|---------------|
| Required argument                      | `greet name`  |
| Optional argument                      | `greet name?` |
| Array argument with 0-n values         | `greet name*` |
| Array argument with at least one value | `greet name+` |

#### Options

A command can take options:

| Description                    | Example                 |
|--------------------------------|-------------------------|
| Simple flag                    | `greet --yell`          |
| Option with an mandatory value | `greet --iterations=`   |
| Option with an optional value  | `greet --iterations[=]` |
| Option that can be used multiple times <br> (the value would be an array) | `greet [--iterations=]*` |
| Option with a shortcut         | `greet -y|--yell`       |

Options are always **optional** (duh). If an option is required, then it should be an argument.

### Command callable

A command can be [any PHP callable](http://php.net/manual/en/language.types.callable.php):

```php
// Closure
$app->command('foo', function () {
    // ...
});

// An object implementing __invoke()
$app->command('foo', new InvokableObject());

// An object method
$app->command('foo', [$object, 'method']);

// A static class method
$app->command('foo', ['MyClass', 'method']);

// A function
$app->command('foo', ['someFunction']);
```

The callable can take as parameters the arguments and options defined in the expression:

```php
$app->command('greet name --yell', function ($name, $yell) {
    // ...
});
```

When running `bin/console greet john --yell`:

- `$name` will be `'john'`
- `$yell` will be `true`

You can also ask for the `$input` and `$output` parameters to get the traditional Symfony `InputInterface` and `OutputInterface` objects:

```php
$app->command(
    'greet name --yell',
    function (InputInterface $input, OutputInterface $output) {
        $name = $input->getArgument('name');
        $yell = $input->getOption('yell');

        // ...
    }
);
```

Finally, you can mix all that. Parameters are detected by their name.

```php
$app->command(
    'greet name --yell',
    function ($name, InputInterface $input, OutputInterface $output) {
        // ...
    }
);
```

## Do more

Silly is just an implementation over the Symfony Console. Read [its documentation](http://symfony.com/doc/current/components/console/introduction.html) to learn everything you can do with it.

## Contributing

See the [CONTRIBUTING](CONTRIBUTING.md) file.

{'fraction_non_alphanumeric': 0.1827555097306354, 'fraction_numerical': 0.0002577651759247326, 'mean_word_length': 2.8057871505640017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4833575', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2327, 'n_words': 682}