Base Command
Base Command is Luminova's comprehensive framework designed for managing command-line operations. As a controller base class, it offers a structured approach to building and executing command-line commands, providing a solid foundation for developing robust and extensible command-line tool (CLIs).
- Class namespace:
\Luminova\Base\BaseCommand
- Parent class: \Luminova\Command\Terminal
- This class is an Abstract class
Properties
Define your command group name. The group will be used as a router capture authentication to ensure that commands belonging to same group are executed accordingly.
protected string $group
Give your command a name.
protected string $name
Describe your command usages, it can either be a string
or an array
of usages examples.
protected string|array $usage
More expressive way to describe your command options and it descriptive message.make the array key your option while the value can be a description of the option.
protected array<string,mixed> $options
Tell more stories about your command by writing a clear description message to help users understand.
protected string $description
Features
- Define custom commands with specific functionalities, each associated with a unique name and description.
- Handle command execution, including parsing command-line arguments, validating inputs, and invoking the appropriate command handler.
- Organize commands into logical modules or groups for improved code reusability and maintainability.
- Customize and extend functionality by creating custom command handlers, adding new command-line options, or integrating with third-party libraries.
- Access controller class functionality just as you would in a web browser, providing seamless integration between command-line and browser-based operations.
Methods
The base command extends the Luminova Terminal class, making all the methods available and ready to use in command controller class.
help
This allows you to override the default help display implementation.When you implement your custom help information display, you must return STATUS_SUCCESS
else return STATUS_ERROR
to tell the framework to keep using the default help implementation.
To call help command: php index.php groupName --help
abstract public help(array $helps): int;
Parameters:
Parameter | Type | Description |
---|---|---|
$helps | array | Receives the command informations. |
Help arguments array keys
class
: Command class name.group
: Command group name.name
: Command identifier name.description
: Command description.usages
: Command usages.options
: Command options.
Return Value
array
- Return Help information for the command group.
Usages
Initialize command line instance before running any commands if you plan to do anything in your Command Controller class.
<?php
namespace App\Controllers;
use \Luminova\Base\BaseCommand;
class PayStackCommand extends BaseCommand
{
//...
}