use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputArgument; class MyCommand extends Command { protected $signature = 'mycommand {arg1} {arg2}'; protected $description = 'My command description.'; public function handle() { $arg1 = $this->argument('arg1'); $arg2 = $this->argument('arg2'); if ($arg1 < 0 || $arg2 < 0) { throw new CommandError('Invalid arguments, args must be positive integers.'); } // Rest of command logic... } protected function configure() { $this->addArgument('arg1', InputArgument::REQUIRED, 'Argument 1 description.'); $this->addArgument('arg2', InputArgument::REQUIRED, 'Argument 2 description.'); } }
use Illuminate\Console\Command; use Illuminate\Console\CommandError; class MyCommand extends Command { protected $signature = 'mycommand'; protected $description = 'My command description.'; public function handle() { try { // Command logic... } catch (CommandError $e) { $this->error($e->getMessage()); } } }Package Library: Illuminate Console (https://github.com/illuminate/console)