pmjones/auto-shell
AutoShell maps CLI command names to PHP command classes in a namespace, reflecting on a main method to parse args/options (scalars or arrays). Add a class in the command directory and it becomes available automatically—no dependencies, minimal setup.
Illuminate\Container), enabling seamless integration with Laravel’s service container.bin/console entry point or adding a custom bin/cli.php.Artisan::command() registrations, though Laravel’s service provider model could still be used for complex dependencies.php bin/console help) mirrors Artisan’s behavior, improving developer experience.__invoke() method inspection) may impact performance in high-frequency CLI tools. Mitigate by benchmarking or caching reflection results.Artisan uses exit(); ensure AutoShell’s return codes align with Laravel’s expectations (e.g., 1 for failures).OptionAlreadyDefined) may need translation to Laravel’s exception hierarchy (e.g., InvalidArgumentException).AutoShell’s factory pattern? Will manual bindings be required for all commands?AutoShell commands and Artisan commands coexist in the same bin/console without conflicts (e.g., command naming collisions)?AutoShell vs. Artisan? Does it support Laravel’s Artisan::fake() or similar?AutoShell be extended to support Laravel-specific features (e.g., command scheduling, events, or middleware)?AutoShell’s API remain stable for Laravel’s long-term roadmap (e.g., PHP 9+, Symfony 7+ dependencies)?php artisan my:tool).php artisan queue:work alternatives).php artisan db:optimize clones).Command component if Laravel’s Artisan is deemed too heavy.bin/backup.php with AutoShell-powered bin/console backup:run.AutoShell for new commands while keeping existing Artisan commands.bin/cli.php alongside artisan for AutoShell-specific commands.AutoShell by:
bin/console to use AutoShell\Console.Artisan::command() registrations with #[Help] attributes.$container->bind('Project\Cli\Command\BackupCommand', fn() => new BackupCommand($backupService));
factory parameter in Console::new() to delegate to Laravel’s container.| Feature | Compatibility Notes |
|---|---|
| Command Discovery | Works with Laravel’s PSR-4 autoloading; ensure composer.json autoload-psr4 is configured. |
| Options/Arguments | Supports all Artisan features (e.g., --option, <argument>) but with stricter typing. |
| Help System | Generates Artisan-like help output; can be customized via #[Help] attributes. |
| Error Handling | Throws exceptions for invalid options/commands; may need wrapping in Laravel’s InvalidCommandException. |
| Exit Codes | Returns int exit codes; ensure alignment with Laravel’s Artisan (e.g., 0 for success). |
| Middleware | No built-in middleware support; workaround via command classes (e.g., inject middleware into constructor). |
| Events | No native event system; use Laravel’s Events facade within command classes. |
| Scheduling | No direct support; use Laravel’s Schedule facade to call AutoShell commands. |
composer require pmjones/auto-shell.bin/cli.php (or modify artisan) with AutoShell\Console configuration.// bin/cli.php
require __DIR__.'/../vendor/autoload.php';
$console = AutoShell\Console::new(
namespace: 'App\Console\Commands',
directory: __DIR__.'/../app/Console/Commands',
factory: fn(string $class) => app()->make($class),
);
exit($console($_SERVER['argv']));
app/Console/Commands/ (e.g., BackupCommand.php).#[Help] and #[Option] attributes.#[Help("Runs database backups.")]
class BackupCommand {
public function __invoke(BackupOptions $options): int { ... }
}
Artisan::fake() for existing tests; extend with AutoShell-specific assertions.$this->artisan('cli:backup', ['--dry-run' => true])->assertExitCode(0);
bin/cli.php is executable (chmod +x bin/cli.php).php cli.php backup:run).Artisan::command() or handle() methods; commands are self-documenting via attributes.bin/cli.php).string vs. int) during development.#[Help], #[Option] may make commands harder to read for developers unfamiliar with the pattern.ClassNotFound) may be less intuitive than Artisan’s.AutoShell provides detailed errors (e.g., OptionAlreadyDefined), but they may not match Laravel’s conventions.Log facade within command classes for structured logging.How can I help you explore Laravel packages today?