Skip to content
Snippets Groups Projects
Commit 0f2fe83c authored by Jared Hancock's avatar Jared Hancock
Browse files

Allow complex specification of arguments

Allow arguments to have sub-command 'options', so an argument like 'action'
can have a specified list of values, each with respective help output.
parent 7a9f8665
Branches
Tags
No related merge requests found
...@@ -157,8 +157,18 @@ class Module { ...@@ -157,8 +157,18 @@ class Module {
if ($this->arguments) { if ($this->arguments) {
echo "\nArguments:\n"; echo "\nArguments:\n";
foreach ($this->arguments as $name=>$help) foreach ($this->arguments as $name=>$help)
$extra = '';
if (is_array($help)) {
if (isset($help['options']) && is_array($help['options'])) {
foreach($help['options'] as $op=>$desc)
$extra .= wordwrap(
"\n $op - $desc", 76, "\n ");
}
$help = $help['help'];
}
echo $name . "\n " . wordwrap( echo $name . "\n " . wordwrap(
preg_replace('/\s+/', ' ', $help), 76, "\n "); preg_replace('/\s+/', ' ', $help), 76, "\n ")
.$extra."\n";
} }
if ($this->epilog) { if ($this->epilog) {
...@@ -198,6 +208,10 @@ class Module { ...@@ -198,6 +208,10 @@ class Module {
foreach (array_keys($this->arguments) as $idx=>$name) foreach (array_keys($this->arguments) as $idx=>$name)
if (!isset($this->_args[$idx])) if (!isset($this->_args[$idx]))
$this->optionError($name . " is a required argument"); $this->optionError($name . " is a required argument");
elseif (is_array($this->arguments[$name])
&& isset($this->arguments[$name]['options'])
&& !isset($this->arguments[$name]['options'][$this->_args[$idx]]))
$this->optionError($name . " does not support such a value");
else else
$this->_args[$name] = &$this->_args[$idx]; $this->_args[$name] = &$this->_args[$idx];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment