Déplacement vers namespace global "jrosset" + support PHP 8

master
Julien Rosset 4 years ago
parent 7f30c1b402
commit 08a5e0b552

@ -1,4 +1,5 @@
# PHPCommandLine
__Command line management library in PHP (CLI)__
![last release](https://badgen.net/packagist/v/darkelfe14728/commandline?label=Last%20release)
@ -8,28 +9,32 @@ __Command line management library in PHP (CLI)__
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
- options (short/long tag) : _-h_ or _--version_
- values : my/path/to/a/file
## Installation
```
composer require darkelfe14728/commandline
composer require jrosset/commandline
```
## 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.
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
<?php
use CommandLine\CommandLine;
use CommandLine\Argument\Option\Flag;
use CommandLine\Argument\Parser\StringParser;
use CommandLine\Argument\Value\Value;
use jrosset\CommandLine\CommandLine;
use jrosset\CommandLine\Argument\Option\Flag;
use jrosset\CommandLine\Argument\Parser\StringParser;
use jrosset\CommandLine\Argument\Value\Value;
$cmdline = new CommandLine('Checker', 'File checker', 'php checker.php');
$cmdline->addDefaultArguments();

@ -2,18 +2,18 @@
require_once '../vendor/autoload.php';
use CommandLine\Argument\Option\Flag;
use CommandLine\Argument\Option\Value;
use CommandLine\Argument\Parser\IntegerParser;
use CommandLine\Argument\Parser\PathParser;
use CommandLine\CommandLine;
use jrosset\CommandLine\Argument\Option\Flag;
use jrosset\CommandLine\Argument\Option\Value;
use jrosset\CommandLine\Argument\Parser\IntegerParser;
use jrosset\CommandLine\Argument\Parser\PathParser;
use jrosset\CommandLine\CommandLine;
$cmdline = new CommandLine('Test', 'Programme de test', 'php test.php');
$cmdline->addDefaultArguments();
$cmdline->addOption(new Flag('array_form', false, 'Sous la forme d\'un tableau ?' . "\n" . 'Ou pas'));
$cmdline->addOption((new Value('days', 'Nombre jour', new IntegerParser(0, 365)))->setDefault(3));
$cmdline->addOption((new Value('years', 'Nombre d\'années', new IntegerParser(0)))->setDefault(5));
$cmdline->addValue((new \CommandLine\Argument\Value\Value('path', 'Chemin sauvegarde images', new PathParser(), true)));
$cmdline->addValue((new \jrosset\CommandLine\Argument\Value\Value('path', 'Chemin sauvegarde images', new PathParser(), true)));
$cmdline->addExitCode(0, 'OK');
$cmdline->addExitCode(255, 'Unexpected error' . "\n" . 'Unknown error');

@ -1,15 +1,15 @@
{
"name": "darkelfe14728/commandline",
"name": "jrosset/commandline",
"description": "Command line management library (CLI)",
"keywords": [ "cli", "parser" ],
"minimum-stability": "dev",
"require": {
"php": "^5.6 || ^7.0"
"php": ">= 7.2"
},
"autoload": {
"psr-4": {
"CommandLine\\": "src/CommandLine/"
"jrosset\\": "src/"
},
"exclude-from-classmap": [ "Tests/" ]
},

6
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "879579c4f4d897535fbe43c7d1a38fc1",
"content-hash": "c4ba533c1f0324fb3d0f3a361f9b5cf8",
"packages": [ ],
"packages-dev": [ ],
"aliases": [ ],
@ -13,8 +13,8 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^5.6 || ^7.0"
"php": ">= 7.2"
},
"platform-dev": [ ],
"plugin-api-version": "1.1.0"
"plugin-api-version": "2.1.0"
}

@ -3,7 +3,7 @@
/**
* Déclaration de la classe CommandLine\Argument\AbstractArgument.
*/
namespace CommandLine\Argument;
namespace jrosset\CommandLine\Argument;
/**
* Classe abstraite pour n'importe quel type de paramètre

@ -2,9 +2,9 @@
/**
* Déclaration de l'interface CommandLine\Argument\IArgument
*/
namespace CommandLine\Argument;
namespace jrosset\CommandLine\Argument;
use CommandLine\Exception\IncorrectParse;
use jrosset\CommandLine\Exception\IncorrectParse;
/**
* Interface que tout argument doit implémenter

@ -2,7 +2,7 @@
/**
* Déclaration de l'interface CommandLine\Argument\IArgumentValueDescription
*/
namespace CommandLine\Argument;
namespace jrosset\CommandLine\Argument;
/**
* Interface à implementer par les arguments qui souhaitent détailler la valeur attendue

@ -2,19 +2,19 @@
/**
* Déclare la classe CommandLine\Argument\Option\Flag.
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
use CommandLine\Argument\ParseResult;
use InvalidArgumentException;
use jrosset\CommandLine\Argument\ParseResult;
/**
* Option de type "flag" contenant True ou False
*
* Si fourni, retournera la valeur inverse de {@see getDefault() getDefault}
*
* @package CommandLine\Argument\Option
* @see FlagReverse
*
* @package CommandLine\Argument\Option
*/
class Flag extends OptionAbstract {
/**

@ -2,7 +2,7 @@
/**
* Déclare la classe CommandLine\Argument\Option\OptionFlagWithReverse.
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
/**
* Option de type "flag" : vaut True ou False avec son tag inversé.

@ -2,9 +2,9 @@
/**
* Déclaration de l'interface CommandLine\Argument\Option\IArgumentOption
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
use CommandLine\Argument\IArgument;
use jrosset\CommandLine\Argument\IArgument;
/**
* Interface à implémenter si l'argument est de type "option"

@ -2,7 +2,7 @@
/**
* Déclaration de l'interface CommandLine\Argument\Option\IArgumentSecondary.
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
/**
* Interface à implémenter si l'argument "option" auto-déclare d'autres arguments

@ -2,10 +2,10 @@
/**
* Déclaration de la classe CommandLine\Argument\Option\OptionAbstract.
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
use CommandLine\Argument\ArgumentAbstract;
use InvalidArgumentException;
use jrosset\CommandLine\Argument\ArgumentAbstract;
/**
* Classe abstraite pour les arguments de type "option" : --xxx / -x

@ -2,12 +2,12 @@
/**
* Déclaration de la classe CommandLine\Argument\Option\Value
*/
namespace CommandLine\Argument\Option;
namespace jrosset\CommandLine\Argument\Option;
use CommandLine\Argument\IArgumentValueDescription;
use CommandLine\Argument\Parser\IValueParser;
use CommandLine\Argument\ParseResult;
use CommandLine\Exception\IncorrectParse;
use jrosset\CommandLine\Argument\IArgumentValueDescription;
use jrosset\CommandLine\Argument\Parser\IValueParser;
use jrosset\CommandLine\Argument\ParseResult;
use jrosset\CommandLine\Exception\IncorrectParse;
use RuntimeException;
/**

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\ParseResult.
*/
namespace CommandLine\Argument;
namespace jrosset\CommandLine\Argument;
/**
* Résultat du parsage d'un argument

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\BooleanParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use RangeException;

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\DecimalParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use InvalidArgumentException;
use RangeException;

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\EnumParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use InvalidArgumentException;
use RangeException;

@ -2,7 +2,7 @@
/**
* Déclare l'interface CommandLine\Argument\Parser\IValueParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
/**
* Interface pour les parseurs

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\IntegerParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use InvalidArgumentException;
use RangeException;

@ -3,7 +3,7 @@
* Déclaration de la classe CommandLine\Argument\Parser\PathParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use InvalidArgumentException;
use UnexpectedValueException;
@ -25,8 +25,10 @@ class PathParser implements IValueParser {
* @var string[] Les expressions régulières pour identifier un chemin
*/
const REGEX_PATH = array(
'unix' => /** @lang PhpRegExp */ '@^(?<directory>/*(?:[^/\n]+(?:/+[^/\n]+)*/+)?)(?<filename>(?<basename>[^/\n]+?)(?:(?:\.(?<extension>[a-zA-Z0-9_]+))|(?:/+))?)$@',
'windows' => /** @lang PhpRegExp */ '@^(?<directory>(?:(?:(?:(?:[a-zA-Z]:)|[\\\\/])[\\\\/])|(?![\\\\/]))(?:[^<>:"/\\\\|?*]+(?:[\\\\/][^<>:"/\\\\|?*]+)*[\\\\/]+)?)(?<filename>(?<basename>[^<>:"/\\\\|?*]+?)(?:(?:\.(?<extension>[a-zA-Z0-9_]+))|(?:[\\\\/]))?)$@',
'unix' => /** @lang PhpRegExp */
'@^(?<directory>/*(?:[^/\n]+(?:/+[^/\n]+)*/+)?)(?<filename>(?<basename>[^/\n]+?)(?:\.(?<extension>[a-zA-Z0-9_]+)|/+)?)$@',
'windows' => /** @lang PhpRegExp */
'@^(?<directory>(?:(?:[a-zA-Z]:|[/])[/]|(?![\\\\/]))(?:[^<>:"/\\\\|?*]+(?:[\\\\/][^<>:"/\\\\|?*]+)*[\\\\/]+)?)(?<filename>(?<basename>[^<>:"/\\\\|?*]+?)(?:\.(?<extension>[a-zA-Z0-9_]+)|[/])?)$@',
);
/**

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\RegexParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use RangeException;

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\StringParser
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
/**
* Parseur vers une chaine de caractères

@ -2,7 +2,7 @@
/**
* Déclaration de la classe CommandLine\Argument\Parser\stdStringClass
*/
namespace CommandLine\Argument\Parser;
namespace jrosset\CommandLine\Argument\Parser;
use stdClass;

@ -2,10 +2,10 @@
/**
* Déclaration de CommandLine\Argument\Value\FixedValue
*/
namespace CommandLine\Argument\Value;
namespace jrosset\CommandLine\Argument\Value;
use CommandLine\Argument\IArgumentValueDescription;
use CommandLine\Argument\ParseResult;
use jrosset\CommandLine\Argument\IArgumentValueDescription;
use jrosset\CommandLine\Argument\ParseResult;
/**
* Argument devant correspondre une valeur fixe

@ -2,9 +2,9 @@
/**
* Déclaration de l'interface CommandLine\Argument\Option\IArgumentValue
*/
namespace CommandLine\Argument\Value;
namespace jrosset\CommandLine\Argument\Value;
use CommandLine\Argument\IArgument;
use jrosset\CommandLine\Argument\IArgument;
/**
* Interface à implémenter si l'argument est de type "valeur"

@ -2,12 +2,12 @@
/**
* Déclaration de CommandLine\Argument\Value\Value
*/
namespace CommandLine\Argument\Value;
namespace jrosset\CommandLine\Argument\Value;
use CommandLine\Argument\IArgumentValueDescription;
use CommandLine\Argument\Parser\IValueParser;
use CommandLine\Argument\ParseResult;
use CommandLine\Exception\IncorrectParse;
use jrosset\CommandLine\Argument\IArgumentValueDescription;
use jrosset\CommandLine\Argument\Parser\IValueParser;
use jrosset\CommandLine\Argument\ParseResult;
use jrosset\CommandLine\Exception\IncorrectParse;
use RangeException;
/**

@ -4,10 +4,10 @@
* Déclaration de la classe CommandLine\Argument\Value\ValueArgument.
*/
namespace CommandLine\Argument\Value;
namespace jrosset\CommandLine\Argument\Value;
use CommandLine\Argument\ArgumentAbstract;
use InvalidArgumentException;
use jrosset\CommandLine\Argument\ArgumentAbstract;
/**
* Classe abstraite pour les paramètres de type "valeur"

@ -3,19 +3,19 @@
* Déclaration de la classe CommandLine\CommandLine
*/
namespace CommandLine;
use CommandLine\Argument\IArgument;
use CommandLine\Argument\IArgumentValueDescription;
use CommandLine\Argument\Option\IArgumentOption;
use CommandLine\Argument\Option\OptionAbstract;
use CommandLine\Argument\ParseResult;
use CommandLine\Argument\Value\IArgumentValue;
use CommandLine\Argument\Value\ValueAbstract;
use CommandLine\Exception\IncorrectParse;
use CommandLine\Exception\MissingArgument;
use CommandLine\Exception\TooMuchValues;
namespace jrosset\CommandLine;
use InvalidArgumentException;
use jrosset\CommandLine\Argument\IArgument;
use jrosset\CommandLine\Argument\IArgumentValueDescription;
use jrosset\CommandLine\Argument\Option\IArgumentOption;
use jrosset\CommandLine\Argument\Option\OptionAbstract;
use jrosset\CommandLine\Argument\ParseResult;
use jrosset\CommandLine\Argument\Value\IArgumentValue;
use jrosset\CommandLine\Argument\Value\ValueAbstract;
use jrosset\CommandLine\Exception\IncorrectParse;
use jrosset\CommandLine\Exception\MissingArgument;
use jrosset\CommandLine\Exception\TooMuchValues;
use ReflectionClass;
use ReflectionException;
use stdClass;

@ -2,11 +2,12 @@
/**
* Déclaration de l'interface d'exception CommandLine\Exception\IException.
*/
namespace CommandLine\Exception;
namespace jrosset\CommandLine\Exception;
/**
* Interface pour toutes les exceptions du module.
*
* @package CommandLine\Exception
*/
interface IException {}
interface IException {
}

@ -2,9 +2,9 @@
/**
* Déclaration de l'exception CommandLine\Exception\IncorrectParse.
*/
namespace CommandLine\Exception;
namespace jrosset\CommandLine\Exception;
use CommandLine\Argument\IArgument;
use jrosset\CommandLine\Argument\IArgument;
use RuntimeException;
/**

@ -2,7 +2,7 @@
/**
* Déclaration de l'exception CommandLine\Exception\MissingArgument
*/
namespace CommandLine\Exception;
namespace jrosset\CommandLine\Exception;
use RuntimeException;

@ -2,7 +2,7 @@
/**
* Déclaration de l'exception CommandLine\Exception\TooMushValues
*/
namespace CommandLine\Exception;
namespace jrosset\CommandLine\Exception;
use RuntimeException;
@ -11,4 +11,5 @@ use RuntimeException;
*
* @package CommandLine\Exception
*/
class TooMuchValues extends RuntimeException implements IException {}
class TooMuchValues extends RuntimeException implements IException {
}
Loading…
Cancel
Save