mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 19:12:42 +00:00
Adding choices to usage and generated help text.
This commit is contained in:
parent
b398877887
commit
ef027f6d0e
3 changed files with 46 additions and 0 deletions
|
@ -74,6 +74,9 @@ class ConsoleInputArgument {
|
||||||
if (!$this->isRequired()) {
|
if (!$this->isRequired()) {
|
||||||
$optional = ' <comment>(optional)</comment>';
|
$optional = ' <comment>(optional)</comment>';
|
||||||
}
|
}
|
||||||
|
if (!empty($this->_choices)) {
|
||||||
|
$optional .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||||
|
}
|
||||||
return sprintf('%s%s%s', $name, $this->_help, $optional);
|
return sprintf('%s%s%s', $name, $this->_help, $optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +87,9 @@ class ConsoleInputArgument {
|
||||||
*/
|
*/
|
||||||
public function usage() {
|
public function usage() {
|
||||||
$name = $this->_name;
|
$name = $this->_name;
|
||||||
|
if (!empty($this->_choices)) {
|
||||||
|
$name = implode('|', $this->_choices);
|
||||||
|
}
|
||||||
if (!$this->isRequired()) {
|
if (!$this->isRequired()) {
|
||||||
$name = '[' . $name . ']';
|
$name = '[' . $name . ']';
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,9 @@ class ConsoleInputOption {
|
||||||
if (!empty($this->_default) && $this->_default !== true) {
|
if (!empty($this->_default) && $this->_default !== true) {
|
||||||
$default = sprintf(__(' <comment>(default: %s)</comment>'), $this->_default);
|
$default = sprintf(__(' <comment>(default: %s)</comment>'), $this->_default);
|
||||||
}
|
}
|
||||||
|
if (!empty($this->_choices)) {
|
||||||
|
$default .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
|
||||||
|
}
|
||||||
if (!empty($this->_short)) {
|
if (!empty($this->_short)) {
|
||||||
$short = ', -' . $this->_short;
|
$short = ', -' . $this->_short;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +99,9 @@ class ConsoleInputOption {
|
||||||
if (!empty($this->_default) && $this->_default !== true) {
|
if (!empty($this->_default) && $this->_default !== true) {
|
||||||
$default = ' ' . $this->_default;
|
$default = ' ' . $this->_default;
|
||||||
}
|
}
|
||||||
|
if (!empty($this->_choices)) {
|
||||||
|
$default = ' ' . implode('|', $this->_choices);
|
||||||
|
}
|
||||||
return sprintf('[%s%s]', $name, $default);
|
return sprintf('[%s%s]', $name, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,40 @@ cake mycommand [-h] [--test] model [other_longer]
|
||||||
model The model to make.
|
model The model to make.
|
||||||
other_longer Another argument. <comment>(optional)</comment>
|
other_longer Another argument. <comment>(optional)</comment>
|
||||||
|
|
||||||
|
TEXT;
|
||||||
|
$this->assertEquals($expected, $result, 'Help does not match');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test help() with options and arguments that have choices.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testHelpWithChoices() {
|
||||||
|
$parser = new ConsoleOptionParser('mycommand', false);
|
||||||
|
$parser->addOption('test', array('help' => 'A test option.', 'choices' => array('one', 'two')))
|
||||||
|
->addArgument('type', array(
|
||||||
|
'help' => 'Resource type.',
|
||||||
|
'choices' => array('aco', 'aro'),
|
||||||
|
'required' => true
|
||||||
|
))
|
||||||
|
->addArgument('other_longer', array('help' => 'Another argument.'));
|
||||||
|
|
||||||
|
$result = $parser->help();
|
||||||
|
$expected = <<<TEXT
|
||||||
|
<info>Usage:</info>
|
||||||
|
cake mycommand [-h] [--test one|two] aco|aro [other_longer]
|
||||||
|
|
||||||
|
<info>Options:</info>
|
||||||
|
|
||||||
|
--help, -h Display this help.
|
||||||
|
--test A test option. <comment>(choices: one|two)</comment>
|
||||||
|
|
||||||
|
<info>Arguments:</info>
|
||||||
|
|
||||||
|
type Resource type. <comment>(choices: aco|aro)</comment>
|
||||||
|
other_longer Another argument. <comment>(optional)</comment>
|
||||||
|
|
||||||
TEXT;
|
TEXT;
|
||||||
$this->assertEquals($expected, $result, 'Help does not match');
|
$this->assertEquals($expected, $result, 'Help does not match');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue