[Console] Allow arrays to be used for lists of shortcuts
This commit is contained in:
parent
7d0b30d579
commit
3bb971e57a
|
@ -34,11 +34,11 @@ class InputOption
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $shortcut The shortcut (can be null)
|
||||
* @param integer $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
||||
* @param string $name The option name
|
||||
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param integer $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
||||
*
|
||||
* @throws \InvalidArgumentException If option mode is invalid or incompatible
|
||||
*
|
||||
|
@ -59,6 +59,9 @@ class InputOption
|
|||
}
|
||||
|
||||
if (null !== $shortcut) {
|
||||
if (is_array($shortcut)) {
|
||||
$shortcut = implode('|', $shortcut);
|
||||
}
|
||||
$shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
|
||||
$shortcuts = array_filter($shortcuts);
|
||||
$shortcut = implode('|', $shortcuts);
|
||||
|
|
|
@ -38,7 +38,7 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument');
|
||||
$option = new InputOption('foo', '-f|-ff|fff');
|
||||
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
|
||||
$option = new InputOption('foo', 'f|ff|-fff');
|
||||
$option = new InputOption('foo', array('f', 'ff', '-fff'));
|
||||
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
|
||||
$option = new InputOption('foo');
|
||||
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
|
||||
|
|
Reference in New Issue