Building Console Commands
Any method tagged with the #[ConsoleCommand]
attribute will be automatically discovered and be available within the console application. By default, you don't have to pass in any parameters to the #[ConsoleCommand]
attribute, since Tempest will use the class and method names to generate a command name:
// app/Package.php use Tempest\Console\ConsoleCommand; final readonly class Package { #[ConsoleCommand] public function all(): void {} #[ConsoleCommand] public function info(string $name): void {} }
These two methods will be accessible via the package:all
and package:info
commands:
~ ./tempest Package package:all package:info <name>
Tempest will use method's parameter list to define the command's definition. For example, this parameter list:
// app/Package.php use Tempest\Console\ConsoleCommand; final readonly class Package { #[ConsoleCommand] public function make( string $name, string $description = '', bool $force = false, ): void {} }
Will generate this command definition:
~ ./tempest Package package:make <name> [description=''] [--force=false]
For more fine-grained control, the #[ConsoleCommand]
attribute takes a couple of optional parameters:
// app/Package.php use Tempest\Console\ConsoleCommand; final readonly class Package { #[ConsoleCommand( name: 'packages:all', description: 'List all packages', aliases: ['pa'], help: 'Extended help text explaining what this command does.' )] public function all(): void {} }
Finally, you can add optional #[ConsoleArgument]
attributes to parameters as well:
use Tempest\Console\ConsoleArgument; public function info( #[ConsoleArgument( description: 'The name of the package', help: 'Extended help text for this argument', aliases: ['n'], )] string $name, ): void {}