Skip to content

Commit 2e3f93d

Browse files
committed
update README.md and example
1 parent fdcd44e commit 2e3f93d

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,33 @@
33
[![Code Climate](https://codeclimate.com/github/JBlond/php-cli/badges/gpa.svg)](https://codeclimate.com/github/JBlond/php-cli) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/438eaa51c0464a689229709cfeb583bb)](https://www.codacy.com/app/leet31337/php-cli?utm_source=github.com&utm_medium=referral&utm_content=JBlond/php-cli&utm_campaign=Badge_Grade)
44

55

6-
php command line / cli scritping classes
6+
## php command line / cli scritping classes
7+
8+
### Example
9+
10+
```PHP
11+
<?php
12+
use jblond\cli\Cli;
13+
use jblond\cli\CliColors;
14+
15+
$cli = new Cli();
16+
$colors = new CliColors();
17+
18+
$string = $colors->getColoredString('This is a test','red','black');
19+
$cli->output($string); // normal
20+
$cli->error($string); // error
21+
22+
// This input requires Hello or world as input
23+
$cli->input('Hello world: ',array('Hello','world'));
24+
25+
// This input requires only test
26+
27+
$cli->input('Test2: ', 'test');
28+
29+
// Question with default N
30+
$answer = $cli->input('Do this? y/N', array('y','n','Y','N'), 'N');
31+
echo $answer;
32+
```
733

834
Inspired by the php.net docs
935
http://php.net/manual/en/features.commandline.io-streams.php

example/cli.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?php
2+
3+
use jblond\cli\Cli;
4+
use jblond\cli\CliColors;
5+
26
require '../src/jblond/cli/Cli.php';
37
require '../src/jblond/cli/CliColors.php';
4-
$cli = new \jblond\cli\Cli();
5-
$colors = new \jblond\cli\CliColors();
8+
9+
$cli = new Cli();
10+
$colors = new CliColors();
11+
612
$string = $colors->getColoredString('This is a test','red','black');
713
$cli->output($string);
814
$cli->error($string);
9-
echo $cli->input('Hello world: ',array('Hello','world'));
10-
echo $cli->input('Test2: ', 'test');
15+
$cli->input('Hello world: ',array('Hello','world'));
16+
$cli->input('Test2: ', 'test');
17+
18+
$answer = $cli->input('Do this? y/N', array('y','n','Y','N'), 'N');
19+
echo $answer;

0 commit comments

Comments
 (0)