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

Auto Shell Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • CLI-Centric Design: Perfect fit for Laravel/PHP applications requiring structured CLI command handling (e.g., artisan-like commands, background jobs, or admin tools).
  • Convention Over Configuration: Aligns with Laravel’s philosophy by auto-discovering commands via PSR-4 namespaces, reducing boilerplate.
  • Dependency Injection Ready: Supports PSR-11 containers (e.g., Laravel’s Illuminate\Container), enabling seamless integration with Laravel’s service container.
  • Lightweight: Zero dependencies (except optional PSR-11) makes it ideal for performance-sensitive CLI tools.

Integration Feasibility

  • Laravel Artisan Compatibility: Can replace or augment Laravel’s Artisan commands by leveraging the same bin/console entry point or adding a custom bin/cli.php.
  • Command Registration: Auto-discovery via namespace/directory eliminates manual Artisan::command() registrations, though Laravel’s service provider model could still be used for complex dependencies.
  • Help System: Built-in help generation (php bin/console help) mirrors Artisan’s behavior, improving developer experience.
  • Type Safety: Supports scalar/array types and custom casting (e.g., booleans), reducing runtime errors compared to manual argument parsing.

Technical Risk

  • Reflection Overhead: Heavy use of reflection (e.g., __invoke() method inspection) may impact performance in high-frequency CLI tools. Mitigate by benchmarking or caching reflection results.
  • Laravel-Specific Quirks:
    • Service Container: Laravel’s container may require adjustments to the factory pattern (e.g., binding command classes explicitly).
    • Artisan Integration: Potential conflicts with Laravel’s existing command resolution (e.g., priority, middleware). Test alongside Artisan commands.
    • Exit Codes: Laravel’s Artisan uses exit(); ensure AutoShell’s return codes align with Laravel’s expectations (e.g., 1 for failures).
  • Error Handling: Custom error messages (e.g., OptionAlreadyDefined) may need translation to Laravel’s exception hierarchy (e.g., InvalidArgumentException).
  • PSR-4 Strictness: Laravel’s autoloading must strictly adhere to PSR-4 for command discovery to work. Non-compliant namespaces/directories will break auto-discovery.

Key Questions

  1. Performance: How does reflection-based parsing compare to Laravel’s compiled Artisan commands in terms of startup time and memory usage?
  2. Dependency Injection: How will Laravel’s service container interact with AutoShell’s factory pattern? Will manual bindings be required for all commands?
  3. Artisan Coexistence: Can AutoShell commands and Artisan commands coexist in the same bin/console without conflicts (e.g., command naming collisions)?
  4. Testing: How will unit/integration tests for CLI commands differ when using AutoShell vs. Artisan? Does it support Laravel’s Artisan::fake() or similar?
  5. Extensibility: Can AutoShell be extended to support Laravel-specific features (e.g., command scheduling, events, or middleware)?
  6. Debugging: How are errors (e.g., missing commands, type mismatches) surfaced to users? Will they align with Laravel’s error formats?
  7. Future-Proofing: Will AutoShell’s API remain stable for Laravel’s long-term roadmap (e.g., PHP 9+, Symfony 7+ dependencies)?

Integration Approach

Stack Fit

  • Laravel Core: Replace or extend Laravel’s Artisan system for CLI commands. Ideal for:
    • Custom admin tools (e.g., php artisan my:tool).
    • Background job management (e.g., php artisan queue:work alternatives).
    • Developer utilities (e.g., php artisan db:optimize clones).
  • Symfony Console: Can serve as a drop-in replacement for Symfony’s Command component if Laravel’s Artisan is deemed too heavy.
  • Legacy Systems: Integrate with existing PHP CLI tools to modernize argument parsing without rewriting core logic.

Migration Path

  1. Pilot Phase:
    • Start with non-critical commands (e.g., internal scripts, non-user-facing tools).
    • Example: Replace a custom bin/backup.php with AutoShell-powered bin/console backup:run.
  2. Artisan Hybrid:
    • Use AutoShell for new commands while keeping existing Artisan commands.
    • Example: Add bin/cli.php alongside artisan for AutoShell-specific commands.
  3. Full Transition:
    • Migrate all CLI commands to AutoShell by:
      • Moving command classes to the configured namespace/directory.
      • Updating bin/console to use AutoShell\Console.
      • Replacing Artisan::command() registrations with #[Help] attributes.
  4. Dependency Injection:
    • Bind command classes to Laravel’s container if they require dependencies:
      $container->bind('Project\Cli\Command\BackupCommand', fn() => new BackupCommand($backupService));
      
    • Use the factory parameter in Console::new() to delegate to Laravel’s container.

Compatibility

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.

Sequencing

  1. Setup:
    • Install via Composer: composer require pmjones/auto-shell.
    • Create bin/cli.php (or modify artisan) with AutoShell\Console configuration.
    • Example:
      // 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']));
      
  2. Command Development:
    • Create classes in app/Console/Commands/ (e.g., BackupCommand.php).
    • Annotate with #[Help] and #[Option] attributes.
    • Example:
      #[Help("Runs database backups.")]
      class BackupCommand {
          public function __invoke(BackupOptions $options): int { ... }
      }
      
  3. Testing:
    • Use Laravel’s Artisan::fake() for existing tests; extend with AutoShell-specific assertions.
    • Example:
      $this->artisan('cli:backup', ['--dry-run' => true])->assertExitCode(0);
      
  4. Deployment:
    • Ensure bin/cli.php is executable (chmod +x bin/cli.php).
    • Document new CLI entry point (e.g., php cli.php backup:run).

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: No need for Artisan::command() or handle() methods; commands are self-documenting via attributes.
    • Centralized Configuration: All command settings (namespace, directory, factory) are in one place (bin/cli.php).
    • Type Safety: Compiler catches type mismatches (e.g., string vs. int) during development.
  • Cons:
    • Reflection Dependency: Changes to command classes (e.g., method signatures) may require cache clearing or restarts.
    • Attribute Overhead: Heavy use of #[Help], #[Option] may make commands harder to read for developers unfamiliar with the pattern.
    • Debugging Complexity: Stack traces for reflection errors (e.g., ClassNotFound) may be less intuitive than Artisan’s.

Support

  • Developer Onboarding:
    • Pros: Attributes and auto-discovery reduce cognitive load for new CLI features.
    • Cons: Developers must understand reflection, attributes, and type hints (advanced PHP features).
  • Troubleshooting:
    • Error Messages: AutoShell provides detailed errors (e.g., OptionAlreadyDefined), but they may not match Laravel’s conventions.
    • Logging: Integrate with Laravel’s Log facade within command classes for structured logging.
  • Documentation:
    • Gap: Limited
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui