ElfSundae / console by ElfSundae

CLI library based on Laravel Artisan for creating PHP console scripts.
18
8
2
Package Data
Maintainer Username: ElfSundae
Maintainer Contact: elf.sundae@gmail.com (Elf Sundae)
Package Create Date: 2017-08-13
Package Last Update: 2017-09-20
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-03-26 15:02:37
Package Statistics
Total Downloads: 18
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 8
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

CLI library based on Laravel Console for creating PHP console application.

Installation

$ composer require elfsundae/console

Usage

First, create a PHP script and make it executable:

#!/usr/bin/env php
<?php

require __DIR__.'/vendor/autoload.php';

$app = new ElfSundae\Console\Application;

// ... register commands

$app->run();

Then, you can register commands using add or command method.

The add method accepts an Illuminate\Console\Command instance or a Symfony\Component\Console\Command\Command instance. The command method may be used for register a Closure based command, it accepts three arguments: the command signature, a Closure which receives the commands arguments and options, and the optional description of the command.

class Example extends Illuminate\Console\Command
{
    protected $signature = 'example
        {--foo=bar : The "foo" option description}';

    protected $description = 'Example command description';

    public function handle()
    {
        $this->comment($this->option('foo'));
    }
}

$app->add(new Example);

$app->command('title {username}', function ($username) {
    $this->comment(title_case($username));
}, 'The `title` command description');

To build a single command application, you may pass true to the second argument of the setDefaultCommand method, or just call the runAsSingle method:

(new ElfSundae\Console\Application)
    ->add($command = new Example)
    ->getApplication()
    ->setDefaultCommand($command->getName(), true)
    ->run();
(new ElfSundae\Console\Application)
    ->add(new Example)
    ->getApplication()
    ->runAsSingle();

Documentation

Testing

$ composer test

License

This package is open-sourced software licensed under the MIT License.