Skip to content

Commit 6945379

Browse files
committed
Adding description() and epilog() to ConsoleOptionParser. Starting to build out addOption.
1 parent d914c0a commit 6945379

File tree

2 files changed

+97
-3
lines changed

2 files changed

+97
-3
lines changed

cake/console/console_option_parser.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
* @subpackage cake.cake.console
2828
*/
2929
class ConsoleOptionParser {
30+
31+
protected $_description = null;
32+
33+
protected $_epilog = null;
34+
35+
protected $_options = array();
36+
37+
protected $_args = array();
38+
3039
/**
3140
* Construct an OptionParser for a given ARGV array.
3241
*
@@ -44,9 +53,59 @@ class ConsoleOptionParser {
4453
* By providing help text for your positional arguments and named arguments, the ConsoleOptionParser
4554
* can generate a help display for you. You can view the help for shells by using the `--help` or `-h` switch.
4655
*
47-
* @param array $args The array of arguments with the Shell/Task stripped off.
4856
*/
49-
public function __construct($args) {
57+
public function __construct() {
58+
59+
}
60+
61+
/**
62+
* Get or set the description text for shell/task
63+
*
64+
* @param string $text The text to set, or null if you want to read
65+
* @return mixed If reading, the value of the description. If setting $this will be returned
66+
*/
67+
public function description($text = null) {
68+
if ($text !== null) {
69+
$this->_description = $text;
70+
return $this;
71+
}
72+
return $this->_description;
73+
}
74+
75+
/**
76+
* Get or set an epilog to the parser. The epilog is added to the end of
77+
* the options and arguments listing when help is generated.
78+
*
79+
* @param string $text Text when setting or null when reading.
80+
* @return mixed If reading, the value of the epilog. If setting $this will be returned.
81+
*/
82+
public function epilog($text = null) {
83+
if ($text !== null) {
84+
$this->_epilog = $text;
85+
return $this;
86+
}
87+
return $this->_epilog;
88+
}
89+
90+
/**
91+
* Add an option to the option parser. Options allow you to define optional or required
92+
* parameters for your console application. Options are defined by the parameters they use.
93+
*
94+
* ### Params
95+
*
96+
* - `shortcut` - The single letter variant for this option, leave undefined for none.
97+
* - `required` - Set to true to force this option to be required. An exception will be thrown
98+
* when this option is not present.
99+
* - `description` - Description for this option.
100+
* - `type` - Require a certain type. Available types are `int` and `string`. If the options
101+
* value is the wrong type an exception will be raised.
102+
* - `default` - The default value for this option. If not defined the default will be null.
103+
*
104+
* @param string $name The name you want to the value to be parsed out as when options are parsed.
105+
* @param array $params An array of parameters that define the behavior of the option
106+
* @return ConsoleOptionParser returns $this.
107+
*/
108+
public function addOption($name, $params = array()) {
50109

51110
}
52111
}

cake/tests/cases/console/console_option_parser.test.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,40 @@
2121
require_once CAKE . 'console' . DS . 'console_option_parser.php';
2222

2323
class ConsoleOptionParserTest extends CakeTestCase {
24-
24+
25+
/**
26+
* test setting the console description
27+
*
28+
* @return void
29+
*/
30+
function testDescription() {
31+
$parser = new ConsoleOptionParser();
32+
$result = $parser->description('A test');
33+
34+
$this->assertEquals($parser, $result, 'Setting description is not chainable');
35+
$this->assertEquals('A test', $parser->description(), 'getting value is wrong.');
36+
}
37+
38+
/**
39+
* test setting the console epliog
40+
*
41+
* @return void
42+
*/
43+
function testEpilog() {
44+
$parser = new ConsoleOptionParser();
45+
$result = $parser->epilog('A test');
46+
47+
$this->assertEquals($parser, $result, 'Setting epilog is not chainable');
48+
$this->assertEquals('A test', $parser->epilog(), 'getting value is wrong.');
49+
}
50+
51+
/**
52+
* test adding an option.
53+
*
54+
* @return void
55+
*/
56+
function testAddOption() {
57+
$parser = new ConsoleOptionParser();
58+
$result = $parser->addOption('test');
59+
}
2560
}

0 commit comments

Comments
 (0)