Skip to content

Commit

Permalink
Implement $*USAGE
Browse files Browse the repository at this point in the history
- Provides default USAGE message the program would generate
- Available as dynvar $*USAGE inside MAIN and USAGE subs; USAGE sub
    can use it as a base to generate custom usage, for example.
- Speculation describes $?USAGE, but we renamed[^1] it since at compile
    time we don't know if we'll ever need it
- Die if user attempts to assign into it

[1] https://irclog.perlgeek.de/perl6-dev/2017-09-23#i_15206569
  • Loading branch information
zoffixznet committed Sep 23, 2017
1 parent 21f05e3 commit 0b15f67
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/Main.pm
@@ -1,7 +1,4 @@
# TODO:
# * $?USAGE
# * Create $?USAGE at compile time
# * Make $?USAGE available globally
# * Command-line parsing
# * Allow both = and space before argument of double-dash args
# * Comma-separated list values
Expand Down Expand Up @@ -185,9 +182,12 @@ my sub MAIN_HELPER($retval = 0) {

# Generate default $?USAGE message
my $usage;
my $?USAGE := Proxy.new(
my $*USAGE := Proxy.new(
FETCH => -> | { $usage || ($usage = gen-usage()) },
STORE => -> | { }
STORE => -> | {
die 'Cannot assign to $*USAGE. Please use `sub USAGE {}` to '
~ 'output custom usage message'
}
);

# Get a list of candidates that match according to the dispatcher
Expand All @@ -211,11 +211,11 @@ my sub MAIN_HELPER($retval = 0) {
# We could not find a user defined USAGE sub!
# Let's display the default USAGE message
if $n<help> {
$*OUT.say($?USAGE);
$*OUT.say($*USAGE);
exit 0;
}
else {
$*ERR.say($?USAGE);
$*ERR.say($*USAGE);
exit 2;
}
}
Expand Down

0 comments on commit 0b15f67

Please sign in to comment.