Skip to content

Commit 39cad9d

Browse files
committed
Allow help to be more compact
1 parent 685c920 commit 39cad9d

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/Options.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function setHelp($help)
7070
}
7171

7272
/**
73-
* Sets the help text for the tools commands itself
73+
* Sets the help text for the tool's commands
7474
*
7575
* @param string $help
7676
*/
@@ -79,6 +79,16 @@ public function setCommandHelp($help)
7979
$this->setup['']['commandhelp'] = $help;
8080
}
8181

82+
/**
83+
* Sets the help text for the tools commands itself
84+
*
85+
* @param boolean $compact
86+
*/
87+
public function setCompactHelp(bool $compact=true)
88+
{
89+
$this->setup['']['compacthelp'] = $compact;
90+
}
91+
8292
/**
8393
* Register the names of arguments for help generation and number checking
8494
*
@@ -346,6 +356,8 @@ public function help()
346356
$hascommands = (count($this->setup) > 1);
347357
$commandhelp = $this->setup[""]["commandhelp"]
348358
?: 'This tool accepts a command as first parameter as outlined below:';
359+
$compacthelp = $this->setup[""]["compacthelp"] ?: false;
360+
349361
foreach ($this->setup as $command => $config) {
350362
$hasopts = (bool)$this->setup[$command]['opts'];
351363
$hasargs = (bool)$this->setup[$command]['args'];
@@ -378,21 +390,26 @@ public function help()
378390
}
379391
$text .= ' ' . $out;
380392
}
381-
$text .= "\n";
393+
if (!$compacthelp) {
394+
$text .= "\n";
395+
}
382396

383397
// usage or command intro
384398
if ($this->setup[$command]['help']) {
385399
$text .= "\n";
386400
$text .= $tf->format(
387401
array($mv, '*'),
388-
array('', $this->setup[$command]['help'] . "\n")
402+
array('', $this->setup[$command]['help']
403+
. (!$compacthelp ?: "\n"))
389404
);
390405
}
391406

392407
// option description
393408
if ($hasopts) {
394409
if (!$command) {
395-
$text .= "\n";
410+
if (!$compacthelp) {
411+
$text .= "\n";
412+
}
396413
$text .= $this->colors->wrap('OPTIONS:', Colors::C_BROWN);
397414
}
398415
$text .= "\n";
@@ -411,12 +428,15 @@ public function help()
411428
$name .= ' <' . $opt['needsarg'] . '>';
412429
}
413430

431+
if (!$compacthelp) {
432+
$text .= "\n";
433+
}
434+
414435
$text .= $tf->format(
415436
array($mv, '30%', '*'),
416437
array('', $name, $opt['help']),
417438
array('', 'green', '')
418439
);
419-
$text .= "\n";
420440
}
421441
}
422442

@@ -447,7 +467,9 @@ public function help()
447467
array($mv, '*'),
448468
array('', $commandhelp)
449469
);
450-
$text .= "\n";
470+
if (!$compacthelp) {
471+
$text .= "\n";
472+
}
451473
}
452474
}
453475

0 commit comments

Comments
 (0)