mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding an exception when a short option is longer than one
character. Having long short options breaks parsing, and doesn't make sense with how short options are used.
This commit is contained in:
parent
10c78c5420
commit
b7391274fb
3 changed files with 28 additions and 1 deletions
|
@ -89,6 +89,11 @@ class ConsoleInputOption {
|
||||||
$this->_default = $default;
|
$this->_default = $default;
|
||||||
$this->_choices = $choices;
|
$this->_choices = $choices;
|
||||||
}
|
}
|
||||||
|
if (strlen($this->_short) > 1) {
|
||||||
|
throw new ConsoleException(
|
||||||
|
__d('cake_console', 'Short options must be one letter.')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,8 @@ App::uses('HelpFormatter', 'Console');
|
||||||
*
|
*
|
||||||
* Options can be defined with both long and short forms. By using `$parser->addOption()`
|
* Options can be defined with both long and short forms. By using `$parser->addOption()`
|
||||||
* you can define new options. The name of the option is used as its long form, and you
|
* you can define new options. The name of the option is used as its long form, and you
|
||||||
* can supply an additional short form, with the `short` option.
|
* can supply an additional short form, with the `short` option. Short options should
|
||||||
|
* only be one letter long. Using more than one letter for a short option will raise an exception.
|
||||||
*
|
*
|
||||||
* Calling options can be done using syntax similar to most *nix command line tools. Long options
|
* Calling options can be done using syntax similar to most *nix command line tools. Long options
|
||||||
* cane either include an `=` or leave it out.
|
* cane either include an `=` or leave it out.
|
||||||
|
@ -52,6 +53,15 @@ App::uses('HelpFormatter', 'Console');
|
||||||
*
|
*
|
||||||
* `cake myshell command -cn`
|
* `cake myshell command -cn`
|
||||||
*
|
*
|
||||||
|
* Short options can be combined into groups as seen above. Each letter in a group
|
||||||
|
* will be treated as a separate option. The previous example is equivalent to:
|
||||||
|
*
|
||||||
|
* `cake myshell command -c -n`
|
||||||
|
*
|
||||||
|
* Short options can also accept values:
|
||||||
|
*
|
||||||
|
* `cake myshell command -c default`
|
||||||
|
*
|
||||||
* ### Positional arguments
|
* ### Positional arguments
|
||||||
*
|
*
|
||||||
* If no positional arguments are defined, all of them will be parsed. If you define positional
|
* If no positional arguments are defined, all of them will be parsed. If you define positional
|
||||||
|
|
|
@ -139,6 +139,18 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
||||||
$this->assertEquals(array('test' => 'value', 'help' => false), $result[0], 'Short parameter did not parse out');
|
$this->assertEquals(array('test' => 'value', 'help' => false), $result[0], 'Short parameter did not parse out');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that adding an option using a two letter short value causes an exception.
|
||||||
|
* As they will not parse correctly.
|
||||||
|
*
|
||||||
|
* @expectedException ConsoleException
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddOptionShortOneLetter() {
|
||||||
|
$parser = new ConsoleOptionParser('test', false);
|
||||||
|
$parser->addOption('test', array('short' => 'te'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test adding and using boolean options.
|
* test adding and using boolean options.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue