Author: jpic
Date: Mon Feb 18 15:21:49 2008
New Revision: 7401
Log:
Fix issue #012561
Modified:
trunk/ConsoleTools/src/input.php
trunk/ConsoleTools/tests/input_test.php
Modified: trunk/ConsoleTools/src/input.php
==============================================================================
--- trunk/ConsoleTools/src/input.php [iso-8859-1] (original)
+++ trunk/ConsoleTools/src/input.php [iso-8859-1] Mon Feb 18 15:21:49 2008
@@ -797,7 +797,7 @@
*/
public function getSynopsis( array $optionNames = null )
{
- $usedOptions = array();
+ $usedOptions = array( 'short' => array(), 'long' => array() );
$allowsArgs = true;
$synopsis = '$ ' . ( isset( $argv ) && sizeof( $argv ) > 0 ? $argv[0]
: $_SERVER['argv'][0] ) . ' ';
foreach ( $this->getOptions() as $option )
@@ -907,9 +907,10 @@
$synopsis = '';
// Break after a nesting level of 2
- if ( $depth++ > 2 || in_array( $option->short, $usedOptions ) ) return
$synopsis;
+ if ( $depth++ > 2 || ( in_array( $option->short, $usedOptions['short']
) && in_array( $option->long, $usedOptions['long'] ) ) ) return $synopsis;
- $usedOptions[] = $option->short;
+ $usedOptions['short'][] = $option->short;
+ $usedOptions['long'][] = $option->long;
$synopsis .= $option->short !== "" ? "-{$option->short}" :
"--{$option->long}";
Modified: trunk/ConsoleTools/tests/input_test.php
==============================================================================
--- trunk/ConsoleTools/tests/input_test.php [iso-8859-1] (original)
+++ trunk/ConsoleTools/tests/input_test.php [iso-8859-1] Mon Feb 18 15:21:49
2008
@@ -2213,7 +2213,36 @@
'Program synopsis not generated correctly.'
);
}
-
+
+ /**
+ * See issue #012561
+ */
+ public function testGetSynopsisLongOptionsWithoutShortNames()
+ {
+ $input = new ezcConsoleInput();
+ $input->registerOption(
+ new ezcConsoleOption(
+ "",
+ "set-dericktory",
+ ezcConsoleInput::TYPE_NONE
+ )
+ );
+
+ $input->registerOption(
+ new ezcConsoleOption(
+ "",
+ "set-directoby",
+ ezcConsoleInput::TYPE_NONE
+ )
+ );
+
+ $this->assertEquals(
+ '$ '.$_SERVER['argv'][0].' [--set-dericktory] [--set-directoby]
[[--] <args>]',
+ $input->getSynopsis(),
+ 'Program synopsis not generated correctly.'
+ );
+ }
+
public function testGetSynopsisNewArgumentsSimple()
{
$this->input->argumentDefinition = new ezcConsoleArguments();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components