From 429df447dd32c52d423c856fd6350954e0d2d60b Mon Sep 17 00:00:00 2001 From: darkelfe14728 Date: Sun, 22 Sep 2019 18:16:41 +0200 Subject: [PATCH] Updating Readme --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f67437..5dc9cde 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,62 @@ + # PHPCommandLine -Command line management library in PHP (CLI) +__Command line management library in PHP (CLI)__ + +![last release](https://badgen.net/github/release/darkelfe14728/PhpCommandLine) +![nb releases](https://badgen.net/github/releases/darkelfe14728/PhpCommandLine) +![licence](https://badgen.net/badge/license/CC%20BY%204.0/red) + +A command-line options parser with configurable expects and help auto generation. + +There is two kind of arguments : + - options (short/long tag) : _-h_ or _--version_ + - values : my/path/to/a/file + +### Description +At first, create a new CommandLine with program name and description. Add options and values by using respectively _addOption_ and _addValue_. +Default options for help (-h / --help) and version (--version) can be add with _addDefaultArguments_ and use _treatDefaultArguments_ for launching associated treatments. + +Treat script arguments with _parse_ : return an object of variables. + +### Example +```php +addDefaultArguments(); + +$cmdline->addOption(new Flag('enhanced', false, 'Deep check ?')); + +$cmdline->addValue(new Value('path', 'File path', new StringParser())); + +var_dump($args = $cmdline->parse()); +$cmdline->treatDefaultArguments($args); +``` + +Would display something like that : + + class stdClass#13 (1) { + public $enhanced => bool(false) + public $path => string("my/path/to/a/file") + } + + +### Automatic help generation +CommandLine provide a generator for command-line of programme. Example : + + Checker + File checker + + php checker.php [OPTIONS] path + Arguments : + path string File path + + Options : + -h --help X Affiche cette aide + --enhanced Deep check ? +