Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for USAGE arg help.
  • Loading branch information
Donald Hunter committed Dec 1, 2015
1 parent 2b5c41e commit d834ab9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/Main.pm
Expand Up @@ -44,6 +44,7 @@ my sub MAIN_HELPER($retval = 0) {
# Generate $?USAGE string (default usage info for MAIN)
my sub gen-usage() {
my @help-msgs;
my %arg-help;

my sub strip_path_prefix($name) {
my $SPEC := $*SPEC;
Expand Down Expand Up @@ -90,13 +91,21 @@ my sub MAIN_HELPER($retval = 0) {
$argument = "[$argument]" if $param.optional;
@positional.push($argument);
}
%arg-help{$argument} = $param.WHY if $param.WHY;
}
if $sub.WHY {
$docs = '-- ' ~ $sub.WHY.contents
}
my $msg = join(' ', $prog-name, @required-named, @optional-named, @positional, $docs // '');
@help-msgs.push($msg);
}

if %arg-help {
@help-msgs.push('');
my $offset = max(%arg-help.map: { .key.chars }) + 4;
@help-msgs.append(%arg-help.map: { ' ' ~ .key ~ ' ' x ($offset - .key.chars) ~ .value });
}

my $usage = "Usage:\n" ~ @help-msgs.map(' ' ~ *).join("\n");
$usage;
}
Expand Down

0 comments on commit d834ab9

Please sign in to comment.