mirror of
https://github.com/n3w/helpers-functions-cli.git
synced 2025-12-19 12:43:22 +00:00
Updated manpage() to include foregroundColour, headingColour, and additional arguments. Removed example argument in favour of including it inside additional.
This commit is contained in:
parent
2387e2a8ea
commit
cfc256347d
1 changed files with 30 additions and 23 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace pointybeard\Helpers\Functions\Cli;
|
namespace pointybeard\Helpers\Functions\Cli;
|
||||||
|
|
||||||
use pointybeard\Helpers\Cli\Input;
|
use pointybeard\Helpers\Cli\Input;
|
||||||
|
use pointybeard\Helpers\Cli\Colour;
|
||||||
use pointybeard\Helpers\Functions\Flags;
|
use pointybeard\Helpers\Functions\Flags;
|
||||||
use pointybeard\Helpers\Functions\Strings;
|
use pointybeard\Helpers\Functions\Strings;
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ if (!function_exists(__NAMESPACE__.'usage')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists(__NAMESPACE__.'manpage')) {
|
if (!function_exists(__NAMESPACE__.'manpage')) {
|
||||||
function manpage(string $name, string $version, string $description, string $example, Input\InputCollection $collection): string
|
function manpage(string $name, string $version, string $description, Input\InputCollection $collection, $foregroundColour=Colour\Colour::FG_DEFAULT, $headingColour=Colour\Colour::FG_WHITE, array $additional=[]): string
|
||||||
{
|
{
|
||||||
$arguments = $options = [];
|
$arguments = $options = [];
|
||||||
|
|
||||||
|
|
@ -74,32 +75,38 @@ if (!function_exists(__NAMESPACE__.'manpage')) {
|
||||||
$options[] = (string) $o;
|
$options[] = (string) $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = implode($arguments, PHP_EOL.' ');
|
$arguments = implode($arguments, PHP_EOL);
|
||||||
$options = implode($options, PHP_EOL.' ');
|
$options = implode($options, PHP_EOL);
|
||||||
|
|
||||||
return sprintf(
|
// Convienence function for wrapping a heading with colour
|
||||||
'%s %s, %s
|
$heading = function(string $input) use ($headingColour) {
|
||||||
%s
|
return Colour\Colour::colourise($input, $headingColour);
|
||||||
|
};
|
||||||
|
|
||||||
Mandatory values for long options are mandatory for short options too.
|
// Convienence function for wrapping input in a specified colour
|
||||||
|
$colourise = function(string $input) use ($foregroundColour) {
|
||||||
Arguments:
|
return Colour\Colour::colourise($input, $foregroundColour);
|
||||||
%s
|
};
|
||||||
|
$sections = [
|
||||||
Options:
|
$colourise(sprintf(
|
||||||
%s
|
"%s %s, %s\r\n%s\r\n",
|
||||||
|
|
||||||
Examples:
|
|
||||||
%s
|
|
||||||
',
|
|
||||||
$name,
|
$name,
|
||||||
$version,
|
$version,
|
||||||
Strings\utf8_wordwrap($description),
|
$description,
|
||||||
usage($name, $collection),
|
usage($name, $collection)
|
||||||
$arguments,
|
)),
|
||||||
$options,
|
$heading('Arguments:'),
|
||||||
$example
|
$colourise($arguments) . PHP_EOL,
|
||||||
);
|
$heading('Options:'),
|
||||||
|
$colourise($options) . PHP_EOL
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($additional as $name => $contents) {
|
||||||
|
$sections[] = $heading("{$name}:");
|
||||||
|
$sections[] = $colourise($contents) . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode($sections, PHP_EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue