/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Console
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Console/README.md (3321B)
[](https://packagist.org/packages/cakephp/console)
[](LICENSE.txt)
# CakePHP Console Library
This library provides a framework for building command line applications from a
set of commands. It provides abstractions for defining option and argument
parsers, and dispatching commands.
# Getting Started
To start, define an an entry point script and Application class that defines
bootstrap logic, and binds your commands. Lets put our entrypoint script in
`bin/tool.php`:
```php
#!/usr/bin/php -q
run($argv));
````
For our `Application` class we can start with:
```php
add('hello', HelloCommand::class);
return $commands;
}
}
```
Next we'll build a very simple `HelloCommand`:
```php
addArgument('name', [
'required' => true,
'help' => 'The name to say hello to',
])
->addOption('color', [
'choices' => ['none', 'green'],
'default' => 'none',
'help' => 'The color to use.'
]);
return $parser;
}
public function execute(Arguments $args, ConsoleIo $io): ?int
{
$color = $args->getOption('color');
if ($color === 'none') {
$io->out("Hello {$args->getArgument('name')}");
} elseif ($color == 'green') {
$io->out("
Hello {$args->getArgument('name')}");
}
return static::CODE_SUCCESS;
}
}
```
Next we can run our command with `php bin/tool.php hello Syd`. To learn more
about the various features we've used in this example read the docs:
* [Option Parsing](https://book.cakephp.org/4/en/console-commands/option-parsers.html)
* [Input & Output](https://book.cakephp.org/4/en/console-commands/input-output.html)