Parser
class
Parser
A parser of CLI options
- Copyright
- 2016 Appertly contributors
- License
- MIT
Instance Properties
Name | Type | Summary |
---|---|---|
$options | OptionSet |
Constructors / Destructors
Returns | Signature and Description |
---|---|
void | __construct ( )Creates a new Parser |
Instance Methods
Returns | Signature and Description |
---|---|
Command | parse ( )Parses a list of arguments into a proper CLI command |
Returns | Signature and Description |
---|---|
void | Safely adds an option to the map, taking into account multiplicity. |
void | parseLong ( , , )Parses a long option (e.g. |
void | parseShort ( , , )Parses a short option (e.g. |
Property Details
$options
OptionSet
$options
Method Details
__construct
__construct
(OptionSet
$options
)Creates a new Parser
Name | Type | Description |
---|---|---|
$options | OptionSet | The options to parse |
addOption
addOption
(string
$label
, mixed
$value
, Option
$option
, Map
<string
,mixed
> $options
)Safely adds an option to the map, taking into account multiplicity.
Name | Type | Description |
---|---|---|
$label | string | The label |
$value | mixed | The value |
$option | Option | The Option object |
$options | Map <string ,mixed > | The map to store values |
parse
parse
(Traversable
<string
> $arguments
)Parses a list of arguments into a proper CLI command
Name | Type | Description |
---|---|---|
$arguments | Traversable <string > | The arguments |
Type | Description |
---|---|
Command | A parsed command |
Type | Conditions |
---|---|
InvalidArgumentException | if the arguments parameter is empty |
UnexpectedValueException | if an unknown option is used or a required value is not supplied |
parseLong
parseLong
(string
$arg
, Vector
<string
> $args
, Map
<string
,mixed
> $options
)Parses a long option (e.g. --dir
)
Name | Type | Description |
---|---|---|
$arg | string | The string argument |
$args | Vector <string > | All remaining arguments |
$options | Map <string ,mixed > | The map to store values |
parseShort
parseShort
(string
$arg
, Vector
<string
> $args
, Map
<string
,mixed
> $options
)Parses a short option (e.g. -d
)
Name | Type | Description |
---|---|---|
$arg | string | The string argument |
$args | Vector <string > | All remaining arguments |
$options | Map <string ,mixed > | The map to store values |