- PHP >= 8.0
- Symfony Console ^6.0
You can install the package via Composer:
composer require nacosvel/console
php ns
Nacosvel Console 1.0.0
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
completion Dump the shell completion script
help Display help for a command
list List commands
<?php
namespace Nacosvel\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class DemoCommand extends Command
{
/**
* @var string|null The default command name
*/
protected static $defaultName = 'demo';
/**
* @var string|null The default command description
*/
protected static $defaultDescription = 'demo description';
protected function handle(): int
{
$this->line($this->argument('name'));
$this->line($this->option('option'));
$this->line('line');
$this->newLine();
$this->info('info');
$this->warn('warn');
$this->error('error');
$this->question('question');
$this->comment('comment');
return self::SUCCESS;
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments(): array
{
return [
['name', InputArgument::OPTIONAL, 'The name of the class', 'demo'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions(): array
{
return [
['option', 'o', InputOption::VALUE_OPTIONAL, 'description', 'default'],
];
}
}
<?php
use Nacosvel\Console;
$console = new Console\Kernel();
$console->add(new Console\Command\DemoCommand());
$console->run();
{
// ...
"extra": {
"nacosvel": {
"commands": [
// "Nacosvel\\Console\\Command\\DemoCommand"
// Add your custom Command
]
}
}
}
php ns demo nacosvel -o console
Nacosvel Console is made available under the MIT License (MIT). Please see License File for more information.