Skip to content

Commit 5669e8f

Browse files
committed
[Add] readme
1 parent 7ac48cd commit 5669e8f

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# PimpleCli
2+
3+
[![Build Status](https://travis-ci.org/Gitory/pimple-cli.svg?branch=master)](https://travis-ci.org/Gitory/pimple-cli)
4+
[![Latest Stable Version](https://poser.pugx.org/gitory/pimple-cli/v/stable.svg)](https://packagist.org/packages/gitory/pimple-cli)
5+
[![License](https://poser.pugx.org/gitory/pimple-cli/license.svg)](https://packagist.org/packages/gitory/pimple-cli)
6+
[![Total Downloads](https://poser.pugx.org/gitory/pimple-cli/downloads.svg)](https://packagist.org/packages/gitory/pimple-cli)
7+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Gitory/pimple-cli/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Gitory/pimple-cli/?branch=master)
8+
9+
[PimpleCli on Packagist](https://packagist.org/packages/gitory/pimple-cli)
10+
11+
PimpleCli is a tool that makes it easy creating command line application.
12+
13+
PimpleCli works with a [Pimple](http://pimple.sensiolabs.org/) container (eg: a [Silex](http://silex.sensiolabs.org) 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.
14+
15+
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](http://symfony.com/doc/current/components/console/introduction.html) to get started.
16+
17+
## Installation
18+
19+
Through Composer :
20+
21+
```json
22+
{
23+
"require": {
24+
"gitory/pimple-cli": "~1.0"
25+
}
26+
}
27+
```
28+
29+
## Examples
30+
31+
### Silex 2
32+
33+
**composer.json**
34+
35+
```json
36+
{
37+
"require": {
38+
"silex/silex": "~2.0@dev",
39+
"gitory/pimple-cli": "~1.0",
40+
"symfony/console": "~2.0"
41+
}
42+
}
43+
44+
```
45+
46+
47+
**GreetCommand.php**
48+
49+
```php
50+
namespace Acme\DemoBundle\Command;
51+
52+
use Symfony\Component\Console\Command\Command;
53+
use Symfony\Component\Console\Input\InputArgument;
54+
use Symfony\Component\Console\Input\InputInterface;
55+
use Symfony\Component\Console\Input\InputOption;
56+
use Symfony\Component\Console\Output\OutputInterface;
57+
58+
class GreetCommand extends Command
59+
{
60+
protected function configure()
61+
{
62+
$this
63+
->setName('demo:greet')
64+
->setDescription('Greet someone')
65+
->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?')
66+
;
67+
}
68+
69+
protected function execute(InputInterface $input, OutputInterface $output)
70+
{
71+
$name = $input->getArgument('name');
72+
$text = 'Hello '.$name;
73+
$output->writeln($text);
74+
}
75+
}
76+
```
77+
78+
**index.php**
79+
80+
```php
81+
require_once __DIR__.'/vendor/autoload.php';
82+
require_once 'GreetCommand.php';
83+
84+
$silexApp = new Silex\Application();
85+
$silexApp->register(new Gitory\PimpleCli\ServiceCommandServiceProvider());
86+
87+
// add your command as services ending in '.command' in your DI
88+
$silexApp['user.new.command'] = function () {
89+
return new Acme\DemoBundle\Command\GreetCommand();
90+
};
91+
92+
$consoleApp = new Symfony\Component\Console\Application($silexApp);
93+
$consoleApp->addCommands($silexApp['command.resolver']->commands());
94+
$consoleApp->run();
95+
96+
```
97+
98+
Launch in Cli : `php index.php demo:greet John`
99+
100+
![command](/doc/screenshots/command.png?raw=true)
101+
![command](/doc/screenshots/help.png?raw=true)

doc/screenshots/command.png

5.26 KB
Loading

doc/screenshots/help.png

49.7 KB
Loading

0 commit comments

Comments
 (0)