Skip to content

Repository files navigation

PimpleCli

Build StatusLatest Stable VersionLicenseTotal DownloadsScrutinizer Code Quality

PimpleCli on Packagist

PimpleCli is a tool that makes it easy creating command line application.

PimpleCli works with a Pimple container (eg: a Silex application) and a Console Application (eg: using http://symfony.com/doc/current/components/console/introduction.html). PimpleCli's role is to discover commands in the Pimple container to make them availlable the the Console Application.

Commands needs to be registered as a service with a name ending in '.command'. The command can be anything (class, callable, etc.) that the console application understand. When using the Symfony\Component\Console\Application command should extends Symfony\Component\Console\Command\Command. You can take a look at the Console Components documentation to get started.

Installation

Through Composer :

{
"require": {
"gitory/pimple-cli": "~1.0"
}
}

Examples

Silex 2

composer.json

{
"require": {
"silex/silex": "~2.0@dev",
"gitory/pimple-cli": "~1.0",
"symfony/console": "~2.0"
}
}

GreetCommand.php

namespaceAcme\DemoBundle\Command;
useSymfony\Component\Console\Command\Command;
useSymfony\Component\Console\Input\InputArgument;
useSymfony\Component\Console\Input\InputInterface;
useSymfony\Component\Console\Input\InputOption;
useSymfony\Component\Console\Output\OutputInterface;
class GreetCommand extends Command
{
protectedfunctionconfigure()
{
$this
->setName('demo:greet')
->setDescription('Greet someone')
->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?')
;
}
protectedfunctionexecute(InputInterface$input, OutputInterface$output)
{
$name = $input->getArgument('name');
$text = 'Hello '.$name;
$output->writeln($text);
}
}

index.php

require_once__DIR__.'/vendor/autoload.php';
require_once'GreetCommand.php';
$silexApp = newSilex\Application();
$silexApp->register(newGitory\PimpleCli\ServiceCommandServiceProvider());
// add your command as services ending in '.command' in your DI$silexApp['user.new.command'] = function () {
returnnewAcme\DemoBundle\Command\GreetCommand();
};
$consoleApp = newSymfony\Component\Console\Application();
$consoleApp->addCommands($silexApp['command.resolver']->commands());
$consoleApp->run();

Launch in Cli : php index.php demo:greet John

commandcommand

About

CLI commands for Pimple applications

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages