Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Commando Laravel Package

nategood/commando

Commando is a lightweight PHP library for building command-line apps: define options and arguments, parse input, generate help text, and validate values. Ideal for quick CLI tools and scripts with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing via Composer: composer require nategood/commando. The library provides a simple, fluent API for building CLI tools—ideal for quick scripts or small Symphony/ Laravel-style console commands. Begin by extending the Commando\Command class or using the Command factory to define arguments and options. The first use case is typically parsing user input for a script: e.g., php myscript.php --name=John --verbose becomes accessible as $command->getArgument('name') and $command->getOption('verbose'). Check the examples/ folder in the repo for minimal working demos.

Implementation Patterns

  • Static Factory for Simplicity: Use Command::create() to bootstrap a command inline:
    $command = Command::create()
      ->addArgument('name', Command::REQUIRED)
      ->addOption('env', 'dev');
    $name = $command->getArgument('name');
    
  • Chained Configuration: Chain addArgument(), addOption(), and setHelp() for clean, readable command definitions.
  • Type Hinting & Validation: Use addArgument(..., Command::OPTIONAL, 'default', 'int') to enable built-in type casting and validation.
  • Reusable Base Classes: Wrap common logic (e.g., DB connection setup, logging) in a base command class that extends Commando\Command.
  • Integration with Laravel: While Laravel has its own console system, Commando is useful for standalone tools, shell helpers, or when porting legacy scripts—just instantiate and run the command outside the framework.

Gotchas and Tips

  • No Automatic Exit: Commando doesn’t call exit() automatically—you must explicitly return or exit() after handling command logic. Forgetting this causes silent script hangs or double execution.
  • Case Sensitivity: Options are case-sensitive (--Verbose ≠ --verbose). Normalize user input in CLI tools if case-insensitivity is expected.
  • Strict Argument Parsing: Positional arguments require exact ordering—mixing flags before/after args can break parsing (e.g., --foo bar baz vs bar --foo baz). Always place positional args at the end.
  • Empty Options Bug: If an option has no value (e.g., --verbose), getOption() returns true, but misusing getValue() may throw exceptions—prefer hasOption() + getOption().
  • Extensibility: Override execute() in a subclass to centralize logic, or hook into onParseError() for custom error messages.
  • PHP 8.1+ Compatibility: The package is unmaintained but still functional; avoid using in new large-scale projects—consider alternatives like Symfony Console for long-term support.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport