Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #265 from softmoth/usage-prog-name
Simplify program name in $?USAGE if in PATH
  • Loading branch information
Mouq committed Apr 18, 2014
2 parents 4b9d8c6 + 6ab0e24 commit 7cf9cad
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/core/Main.pm
Expand Up @@ -67,7 +67,22 @@ my sub MAIN_HELPER($retval = 0) is hidden_from_backtrace {
# Generate $?USAGE string (default usage info for MAIN)
my sub gen-usage () {
my @help-msgs;
my $prog-name = $*PROGRAM_NAME eq '-e' ?? "-e '...'" !! $*PROGRAM_NAME;

my sub strip_path_prefix($name) {
my ($vol, $dir, $base) = IO::Spec.splitpath($name);
$dir = IO::Spec.canonpath($dir);
for IO::Spec.path() -> $elem {
if IO::Spec.catpath($vol, $elem, $base).IO.x {
return $base if IO::Spec.canonpath($elem) eq $dir;
# Shadowed command found in earlier PATH element
return $name;
}
}
# Not in PATH
return $name;
}

my $prog-name = $*PROGRAM_NAME eq '-e' ?? "-e '...'" !! strip_path_prefix($*PROGRAM_NAME);
for $m.candidates -> $sub {
my (@required-named, @optional-named, @positional, $docs);
for $sub.signature.params -> $param {
Expand Down

0 comments on commit 7cf9cad

Please sign in to comment.