c9s / GetOptionKit

An object-oriented option parser library for PHP, which supports type constraints, flag, multiple flag, multiple values, required value checking

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ContinuousOptionParser does not support incremental options

Programie opened this issue · comments

In the normal OptionParser you can define incremental options (e.g. -v or -vvv). The option value will then be set to the number of occurrences of the option (e.g. 1 or 3).

In case of the ContinuousOptionParser an incremental option always has a value of 1 even if it is given multiple times (e.g. -vv should set the value to 2).

Example:

$options = new OptionCollection;

//$options->add("v|verbose")->isa("number")->incremental();// Setting isa("number") will throw an InvalidOptionValue exception "Invalid value for -v, --verbose. Requires a type Number."
$options->add("v|verbose")->incremental();// This works but only sets the value to true even if specified multiple times

$parser = new ContinuousOptionParser($options);// Replace ContinuousOptionParser with OptionParser and everything works as expected

$result = $parser->parse($argv);

var_dump($result->keys["verbose"]->value);// Returns true (if the verbose option has been specified at least once)

Fixed in master, released in 2.2.6