Permalink
Browse files

allow 2nd param to Getopti::on to be description when 1st is Getopti\…

…Option object
  • Loading branch information...
Braden Schaeffer
Braden Schaeffer committed Jun 28, 2011
1 parent 6235603 commit ab3f245fbdadd7ca1307919140f2c63e584c8842
Showing with 27 additions and 3 deletions.
  1. +19 −1 Getopti.php
  2. +8 −2 Test/GetoptiTest.php
View
@@ -190,9 +190,23 @@ public function usage($usage)
* Adds options to the switcher and registers them with the automated
* help output.
*
+ * Using with passed parameters:
+ *
+ * <code>
+ * $opts->on($opts, $parameter, $description, $callback);
+ * </code>
+ *
+ * Using with a Getopti\Option object:
+ *
+ * <code>
+ * $option = new Getopti\Option::build($opts, $parameter, $callback);
+ * $opts->on($option, $description);
+ * </code>
+ *
* @access public
* @param mixed string (single option), array (multiple), or a Getopt\Option object
- * @param mixed the parameter string (i.e. ITEM or [ITEM]) or array with optional default
+ * @param mixed the parameter string (i.e. ITEM or [ITEM]) or array with optional default,
+ * or an description if the first option is a Getopti\Option object
* @param string description of what the option does
* @param closure a callback function to be invoked when the option is specified
* @return void
@@ -205,6 +219,10 @@ public function on($opts, $parameter = NULL, $description = '', $callback = NULL
{
$option = Getopti\Option::build($opts, $parameter, $callback);
}
+ else
+ {
+ $description = $parameter;
+ }
$this->switcher->add($option);
$this->output->option(
View
@@ -98,20 +98,26 @@ public function on($option, $short = FALSE, $long = FALSE)
* @test
* @covers Getopti::on
*/
- public function on_allows_an_Option_object_as_only_parameter()
+ public function on_allows_an_Option_object_as_parameter()
{
$option = Getopti\Option::build('a');
try
{
- $this->opts->on($option);
+ $this->opts->on($option, 'a simple description');
}
catch(Exception $e)
{
$this->fail(
'The Getopti::on method did not allow a Getopti\Option object as the only parameter.'
);
}
+
+ $this->assertContains(
+ 'a simple description', $this->opts->help(),
+ 'When passing a Getopti\\Option object as the first parameter, ' .
+ '$opts->on did not use the 2nd parameter as the description.'
+ );
}
/**

0 comments on commit ab3f245

Please sign in to comment.