diff --git a/src/Options.php b/src/Options.php index 4d8b44d..ea36803 100644 --- a/src/Options.php +++ b/src/Options.php @@ -69,6 +69,26 @@ public function setHelp($help) $this->setup['']['help'] = $help; } + /** + * Sets the help text for the tool's commands + * + * @param string $help + */ + public function setCommandHelp($help) + { + $this->setup['']['commandhelp'] = $help; + } + + /** + * Sets the help text for the tools commands itself + * + * @param boolean $compact + */ + public function setCompactHelp($compact=true) + { + $this->setup['']['compacthelp'] = $compact; + } + /** * Register the names of arguments for help generation and number checking * @@ -334,6 +354,10 @@ public function help() $text = ''; $hascommands = (count($this->setup) > 1); + $commandhelp = $this->setup[""]["commandhelp"] + ?: 'This tool accepts a command as first parameter as outlined below:'; + $compacthelp = $this->setup[""]["compacthelp"] ?: false; + foreach ($this->setup as $command => $config) { $hasopts = (bool)$this->setup[$command]['opts']; $hasargs = (bool)$this->setup[$command]['args']; @@ -345,7 +369,9 @@ public function help() $text .= ' ' . $this->bin; $mv = 2; } else { - $text .= "\n"; + if (!$compacthelp) { + $text .= "\n"; + } $text .= $this->colors->wrap(' ' . $command, Colors::C_PURPLE); $mv = 4; } @@ -366,21 +392,24 @@ public function help() } $text .= ' ' . $out; } - $text .= "\n"; + if (!$compacthelp) { + $text .= "\n"; + } // usage or command intro if ($this->setup[$command]['help']) { $text .= "\n"; $text .= $tf->format( array($mv, '*'), - array('', $this->setup[$command]['help'] . "\n") + array('', $this->setup[$command]['help'] + . ($compacthelp ? '' : "\n")) ); } // option description if ($hasopts) { if (!$command) { - $text .= "\n"; + $text .= "\n"; $text .= $this->colors->wrap('OPTIONS:', Colors::C_BROWN); } $text .= "\n"; @@ -399,12 +428,15 @@ public function help() $name .= ' <' . $opt['needsarg'] . '>'; } + if (!$compacthelp) { + $text .= "\n"; + } + $text .= $tf->format( array($mv, '30%', '*'), array('', $name, $opt['help']), array('', 'green', '') ); - $text .= "\n"; } } @@ -414,7 +446,9 @@ public function help() $text .= "\n"; $text .= $this->colors->wrap('ARGUMENTS:', Colors::C_BROWN); } - $text .= "\n"; + if (!$compacthelp) { + $text .= "\n"; + } foreach ($this->setup[$command]['args'] as $arg) { $name = '<' . $arg['name'] . '>'; @@ -433,9 +467,11 @@ public function help() $text .= "\n"; $text .= $tf->format( array($mv, '*'), - array('', 'This tool accepts a command as first parameter as outlined below:') + array('', $commandhelp) ); - $text .= "\n"; + if (!$compacthelp) { + $text .= "\n"; + } } }