From 685c920badc4aa5fa19a58fb9f8fdd97f563ac29 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sat, 11 May 2019 16:55:55 -0400 Subject: [PATCH 1/2] Add the ability to change the help text for commands --- src/Options.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Options.php b/src/Options.php index 4d8b44d..72e9659 100644 --- a/src/Options.php +++ b/src/Options.php @@ -69,6 +69,16 @@ public function setHelp($help) $this->setup['']['help'] = $help; } + /** + * Sets the help text for the tools commands itself + * + * @param string $help + */ + public function setCommandHelp($help) + { + $this->setup['']['commandhelp'] = $help; + } + /** * Register the names of arguments for help generation and number checking * @@ -334,6 +344,8 @@ public function help() $text = ''; $hascommands = (count($this->setup) > 1); + $commandhelp = $this->setup[""]["commandhelp"] + ?: 'This tool accepts a command as first parameter as outlined below:'; foreach ($this->setup as $command => $config) { $hasopts = (bool)$this->setup[$command]['opts']; $hasargs = (bool)$this->setup[$command]['args']; @@ -433,7 +445,7 @@ 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"; } From 9830a2bef319e50994aa62555e837d71c9caef73 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sat, 11 May 2019 17:14:14 -0400 Subject: [PATCH 2/2] Allow help to be more compact --- src/Options.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Options.php b/src/Options.php index 72e9659..ea36803 100644 --- a/src/Options.php +++ b/src/Options.php @@ -70,7 +70,7 @@ public function setHelp($help) } /** - * Sets the help text for the tools commands itself + * Sets the help text for the tool's commands * * @param string $help */ @@ -79,6 +79,16 @@ 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 * @@ -346,6 +356,8 @@ public function help() $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']; @@ -357,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; } @@ -378,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"; @@ -411,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"; } } @@ -426,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'] . '>'; @@ -447,7 +469,9 @@ public function help() array($mv, '*'), array('', $commandhelp) ); - $text .= "\n"; + if (!$compacthelp) { + $text .= "\n"; + } } }