Skip to content
Permalink
Browse files

Starting to implement options and option parsing.

  • Loading branch information...
markstory committed Oct 8, 2010
1 parent 6945379 commit d5d9adb92b0f9774da708a8e2a912549f0625997
Showing with 40 additions and 5 deletions.
  1. +23 −3 cake/console/console_option_parser.php
  2. +17 −2 cake/tests/cases/console/console_option_parser.test.php
@@ -98,14 +98,34 @@ public function epilog($text = null) {
* when this option is not present.
* - `description` - Description for this option.
* - `type` - Require a certain type. Available types are `int` and `string`. If the options
* value is the wrong type an exception will be raised.
* value is the wrong type an exception will be raised. Leave undefined to accept anything.
* - `default` - The default value for this option. If not defined the default will be null.
*
* @param string $name The name you want to the value to be parsed out as when options are parsed.
* @param string $name The long name you want to the value to be parsed out as when options are parsed.
* @param array $params An array of parameters that define the behavior of the option
* @return ConsoleOptionParser returns $this.
* @return returns $this.
*/
public function addOption($name, $params = array()) {
$defaults = array(
'shortcut' => null,
'required' => false,
'description' => '',
'type' => null,
'default' => null
);
$this->_options[$name] = array_merge($defaults, $params);
return $this;
}
/**
* Parse the argv array into a set of params and args.
*
* @param array $argv Array of args (argv) to parse
* @return Array array($params, $args)
*/
public function parse($argv) {
$params = $args = array();
return array($params, $args);
}
}
@@ -49,12 +49,27 @@ function testEpilog() {
}
/**
* test adding an option.
* test adding an option returns self.
*
* @return void
*/
function testAddOption() {
function testAddOptionReturnSelf() {
$parser = new ConsoleOptionParser();
$result = $parser->addOption('test');
$this->assertEquals($parser, $result, 'Did not return $this from addOption');
}
/**
* test adding an option and using the shortcut value for parsing.
*
* @return void
*/
function testAddOptionShortcut() {
$parser = new ConsoleOptionParser();
$parser->addOption('test', array(
'shortcut' => 't'
));
$result = $parser->parse(array('-t', 'value'));
$this->assertEqual(array('test' => 'value'), $result[0], 'Short parameter did not parse out');
}
}

0 comments on commit d5d9adb

Please sign in to comment.
You can’t perform that action at this time.