diff options
Diffstat (limited to 'vendor/splitbrain/php-cli/src/Options.php')
-rw-r--r-- | vendor/splitbrain/php-cli/src/Options.php | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/vendor/splitbrain/php-cli/src/Options.php b/vendor/splitbrain/php-cli/src/Options.php index 74dae2be4..5ee6b6931 100644 --- a/vendor/splitbrain/php-cli/src/Options.php +++ b/vendor/splitbrain/php-cli/src/Options.php @@ -31,6 +31,9 @@ class Options /** @var Colors for colored help output */ protected $colors; + /** @var string newline used for spacing help texts */ + protected $newline = "\n"; + /** * Constructor * @@ -49,7 +52,8 @@ class Options '' => array( 'opts' => array(), 'args' => array(), - 'help' => '' + 'help' => '', + 'commandhelp' => 'This tool accepts a command as first parameter as outlined below:' ) ); // default command @@ -78,6 +82,26 @@ class Options } /** + * Sets the help text for the tools commands itself + * + * @param string $help + */ + public function setCommandHelp($help) + { + $this->setup['']['commandhelp'] = $help; + } + + /** + * Use a more compact help screen with less new lines + * + * @param bool $set + */ + public function useCompactHelp($set = true) + { + $this->newline = $set ? '' : "\n"; + } + + /** * Register the names of arguments for help generation and number checking * * This has to be called in the order arguments are expected @@ -342,6 +366,8 @@ class Options $text = ''; $hascommands = (count($this->setup) > 1); + $commandhelp = $this->setup['']["commandhelp"]; + foreach ($this->setup as $command => $config) { $hasopts = (bool)$this->setup[$command]['opts']; $hasargs = (bool)$this->setup[$command]['args']; @@ -353,7 +379,7 @@ class Options $text .= ' ' . $this->bin; $mv = 2; } else { - $text .= "\n"; + $text .= $this->newline; $text .= $this->colors->wrap(' ' . $command, Colors::C_PURPLE); $mv = 4; } @@ -374,14 +400,14 @@ class Options } $text .= ' ' . $out; } - $text .= "\n"; + $text .= $this->newline; // 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'] . $this->newline) ); } @@ -412,7 +438,7 @@ class Options array('', $name, $opt['help']), array('', 'green', '') ); - $text .= "\n"; + $text .= $this->newline; } } @@ -422,7 +448,7 @@ class Options $text .= "\n"; $text .= $this->colors->wrap('ARGUMENTS:', Colors::C_BROWN); } - $text .= "\n"; + $text .= $this->newline; foreach ($this->setup[$command]['args'] as $arg) { $name = '<' . $arg['name'] . '>'; @@ -441,9 +467,9 @@ class Options $text .= "\n"; $text .= $tf->format( array($mv, '*'), - array('', 'This tool accepts a command as first parameter as outlined below:') + array('', $commandhelp) ); - $text .= "\n"; + $text .= $this->newline; } } |