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

Plain Commands Laravel Package

alexeyshockov/plain-commands

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require alexeyshockov/plain-commands
    

    (Note: Since the package is archived, verify compatibility with your Laravel version.)

  2. Basic Command Definition Create a command class in app/Console/Commands:

    use Alexeyshockov\PlainCommands\Command;
    
    class ExampleCommand extends Command
    {
        protected $name = 'example:greet';
        protected $description = 'Greets the user';
    
        public function handle()
        {
            $this->info('Hello, Laravel!');
        }
    }
    
  3. Register the Command Add the command to app/Console/Kernel.php:

    protected $commands = [
        \App\Console\Commands\ExampleCommand::class,
    ];
    
  4. Run the Command Execute via Artisan:

    php artisan example:greet
    

First Use Case

Use this package to rapidly scaffold CLI tools without boilerplate. Ideal for:

  • One-off scripts (e.g., data migration helpers).
  • Internal tools (e.g., queue:flush-all).
  • Extending Laravel’s built-in Artisan commands with minimal overhead.

Implementation Patterns

1. Command Structure

Leverage the Command base class for consistency:

class MyCommand extends Command
{
    // Required: Command name (e.g., 'app:process')
    protected $name = 'app:process';

    // Required: Description (shown in `artisan list`)
    protected $description = 'Processes X';

    // Optional: Arguments/options
    protected $arguments = [
        ['input', InputArgument::REQUIRED, 'Input file path'],
    ];

    protected $options = [
        ['force', 'f', InputOption::VALUE_NONE, 'Force overwrite'],
    ];

    public function handle()
    {
        $input = $this->argument('input');
        $force = $this->option('force');

        // Business logic here
    }
}

2. Input/Output Helpers

Use Symfony’s Console components via $this:

// Output
$this->info('Success!');
$this->error('Failed!');
$this->question('Confirm?', 'y');

// Input
$name = $this->ask('Enter name');
$confirm = $this->confirm('Proceed?', false);

3. Dependency Injection

Inject services via Laravel’s container:

public function __construct(MyService $service)
{
    $this->service = $service;
}

4. Command Groups

Organize commands with namespaces:

// Command name: `app:user:create`
protected $name = 'app:user:create';

Run all app:user:* commands with:

php artisan app:user

5. Event Integration

Trigger Laravel events from commands:

event(new UserCreated($user));

6. Testing

Test commands via Artisan::call():

$exitCode = Artisan::call('example:greet');
$this->assertEquals(0, $exitCode);

Gotchas and Tips

Pitfalls

  1. Archived Package Risk

    • No active maintenance; fork or migrate to Laravel’s built-in commands if critical.
    • Check for breaking changes in Symfony Console (e.g., v6+).
  2. No Built-in Scheduling

    • Unlike Laravel’s Schedule, this package doesn’t integrate with app/Console/Kernel.php's $schedule. Use Laravel’s native scheduling instead.
  3. Limited Validation

    • Manual validation required (e.g., no built-in rules for arguments/options). Use Laravel’s Validator or Symfony’s ValidatorInterface.
  4. Namespace Collisions

    • Avoid naming conflicts with Laravel’s core commands (e.g., cache:clear). Prefix with your app name (e.g., app:cache:clear).

Debugging Tips

  • Verbose Output: Use $this->verbose('Debug info') for detailed logs.
  • Exit Codes: Return non-zero for failures:
    return 1; // Fails the command
    
  • Symfony Console Docs: Refer to Symfony’s Console Component for advanced features (e.g., tables, progress bars).

Extension Points

  1. Custom Helpers Extend the base class for shared logic:

    class BaseCommand extends Command
    {
        protected function log($message) { /* ... */ }
    }
    
  2. Input Validation Reuse Laravel’s Validator:

    $validator = Validator::make(['name' => $this->argument('name')], ['name' => 'required|string']);
    
  3. Interactive Prompts Chain methods for complex workflows:

    $name = $this->ask('Name');
    $confirm = $this->confirm(sprintf('Create %s?', $name));
    
  4. Configuration Load config via Laravel’s config() helper:

    $timeout = config('app.command_timeout');
    

Performance

  • Avoid Heavy Logic: Commands should be lightweight. Offload processing to queues/jobs if needed.
  • Cache Dependencies: Inject Cache facade to avoid repeated I/O:
    public function __construct(Cache $cache) { /* ... */ }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky