2017 © Pedro Peláez
 

library lib-cli

CLI library of the Ride framework

image

ride/lib-cli

CLI library of the Ride framework

  • Friday, October 14, 2016
  • by ride-user
  • Repository
  • 7 Watchers
  • 0 Stars
  • 3,075 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 2 % Grown

The README.md

Ride: CLI Library

CLI library of the PHP Ride framework., (*1)

Command

The Command interface is what you will implement to extend the CLI. It contains the logic for your action., (*2)

You can check this code sample of a command:, (*3)

<?php

use ride\library\cli\command\AbstractCommand;

class MyCommand extends AbstractCommand {

    public function __construct() {
        parent::__construct('name', 'description');

        // Define a required argument
        $this->addArgument('arg1', 'description');

        // Define a optional argument
        $this->addArgument('arg2', 'description', false);

        // Define a dynamic argument
        // The value is the rest of the command line.
        // There are no more arguments allowed after a dynamic one
        $this->addArgument('arg3', 'description', false, true);

        // Define a flag (always optional)
        $this->addFlag('flag', 'description');
    }

    public function execute() {
        // Get the defined input values
        $arg1 = $this->input->getArgument('arg1');
        $arg2 = $this->input->getArgument('arg2', 'default');
        $arg3 = $this->input->getArgument('arg3');
        $flag = $this->input->getFlag('flag');

        if ($this->input->isInteractive()) {
            // Interactive shell, read some input interactive
            $arg4 = $this->input->read($this->output, 'my prompt: ');
        }            

        // Write some output
        $this->output->write("output");
        $this->output->writeLine("output line");
        $this->output->writeError("error output");
        $this->output->writeErrorLine("error output line");
    }

}

Code Sample

Check this code sample to create a CLI from this library:, (*4)

<?php

use ride\library\cli\command\CommandContainer;
use ride\library\cli\input\PhpInput;
use ride\library\cli\output\PhpOutput;
use ride\library\cli\Cli;
use ride\library\cli\CommandInterpreter;

// Create a command container and add some commands to it
$commandContainer = new CommandContainer();
$commandContainer->addCommand(new MyCommand()); // the command from previous sample

// Create a command interpreter from the container
$commandInterpreter = new CommandInterpreter($commandContainer);

// Create your input and output interface
$input = new PhpInput(); // ReadlineInput for interactive shell with auto completion and history 
$output = new PhpOutput();

// and create and run the cli
$cli = new Cli($commandInterpreter);
$cli->setInput($input); // input for the commands
$cli->setOutput($output);

$cli->run($input); // input for the CLI, you can use ArgumentInput to parse the command line

// exit with a proper code
exit($cli->getExitCode());

The Versions

14/10 2016

dev-master

9999999-dev

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

14/10 2016

dev-develop

dev-develop

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

14/10 2016

1.0.4

1.0.4.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

17/08 2016

1.0.3

1.0.3.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

10/08 2016

1.0.2

1.0.2.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

06/08 2016

1.0.1

1.0.1.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

24/06 2016

1.0.0

1.0.0.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

02/03 2015

0.2.0

0.2.0.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

19/12 2014

0.1.2

0.1.2.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

01/04 2014

0.1.1

0.1.1.0

CLI library of the Ride framework

  Sources   Download

MIT

by Joris Vandeweerd

10/10 2013

0.1.0

0.1.0.0

CLI library of the Pallo framework

  Sources   Download

MIT

by Joris Vandeweerd