Skip to content

Commit

Permalink
Provide help via POD documentation.
Browse files Browse the repository at this point in the history
Fix issue tadzik#91.

The idea is to let the help branch to introspect the POD documentation
for a specific command in order to see if some documentation can be found.
If documentation can be found, it is shown. This allows for:
- invoking help on subcommands, for instance
  rakudobrew help nuke
- invoking help without any argument, that as already done
  simply prints the list of commands
- invoking an alien command, that results in printing out
  the list of available commands.

This requires an explicit dependency on Pod::Usage.

The help is provided as POD documentation with sections named 'COMMAND'
and the name of the command as passed to rakudobrew. The nuke command
has been introduced as an example.
  • Loading branch information
fluca1978 committed Oct 7, 2017
1 parent 34bf04c commit 4439a4b
Showing 1 changed file with 81 additions and 20 deletions.
101 changes: 81 additions & 20 deletions bin/rakudobrew
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,62 @@ EOT
}
}
} else {
say "Usage:";
say "$brew_name current";
say "$brew_name list-available";
say "$brew_name build " , (join "|", available_backends(), "all"), " [tag|branch|sha-1]", " [--configure-opts=]";
say "$brew_name build zef";
say "$brew_name triple [rakudo-ver [nqp-ver [moar-ver]]]";
say "$brew_name rehash";
say "$brew_name switch ", (join "|", available_backends());
say "$brew_name nuke ", (join "|", available_backends());
say "$brew_name self-upgrade";
say "$brew_name test [", (join "|", available_backends(), "all"), "]";
say "$brew_name exec <command> [command-args]";
say "$brew_name init";
say "$brew_name shell [--unset|version]";
say "$brew_name local [version]";
say "$brew_name global [version]";
say "$brew_name version";
say "$brew_name versions # or $brew_name list";
say "$brew_name which <command>";
say "$brew_name whence [--path] <command>";
# here we come for the 'help' command or
# nothing the program has been capable to
# understand

if ( @ARGV == 1 ){
# the user wants help for a specific command
# e.g., rakudobrew help list
my $command = $ARGV[ 0 ];
say "$brew_name help [$command]";

require Pod::Usage;
my $help_text = "";
open my $pod_fh, ">", \$help_text;

Pod::Usage::pod2usage(
-exitval => "NOEXIT", # do not terminate this script!
-verbose => 99, # 99 = indicate the sections
-sections => "COMMAND: " . lc( $command ), # e.g.: COMMAND: list
-output => $pod_fh, # filehandle reference
-noperldoc => 1 # do not call perldoc for the high verbosity level (99)
);

# some cleanup
$help_text =~ s/\A[^\n]+\n//s;
$help_text =~ s/^ //gm;

$help_text = "Cannot find documentation for [$command]!" if ($help_text =~ /\A\s*\Z/);
close $pod_fh;
say $help_text;
exit;
}
else {
# here the user does not want any specific help
# or we cannot understand what he wants, print
# a generic usage message
say "Usage:";
say "$brew_name current";
say "$brew_name list-available";
say "$brew_name build " , (join "|", available_backends(), "all"), " [tag|branch|sha-1]", " [--configure-opts=]";
say "$brew_name build zef";
say "$brew_name triple [rakudo-ver [nqp-ver [moar-ver]]]";
say "$brew_name rehash";
say "$brew_name switch ", (join "|", available_backends());
say "$brew_name nuke ", (join "|", available_backends());
say "$brew_name self-upgrade";
say "$brew_name test [", (join "|", available_backends(), "all"), "]";
say "$brew_name exec <command> [command-args]";
say "$brew_name init";
say "$brew_name shell [--unset|version]";
say "$brew_name local [version]";
say "$brew_name global [version]";
say "$brew_name version";
say "$brew_name versions # or $brew_name list";
say "$brew_name which <command>";
say "$brew_name whence [--path] <command>";
}
}

exit;
Expand Down Expand Up @@ -940,3 +976,28 @@ sub get_git_url {
return "${protocol}://${host}/${user}/${project}.git";
}
}


__END__
=head1 NAME
rakudobrew - Perl 6 environment manager
=head1 SYNOPSIS
rakudobrew command syntax:
rakuydobrew <command> [options] [arguments]
=head1 COMMAND: nuke
Usage: rakudobrew nuke <version>
The C<nuke> command totally destroy the specified Perl 6 version from your repository
of installed backends.
=cut

0 comments on commit 4439a4b

Please sign in to comment.