Skip to content

Commit ec139cb

Browse files
committed
Document sub MAIN usage cares about WHY on candidates
Looking at the code it also cares about .WHYs on individual parameters, but I don't know Pod enough to figure out how to set those.
1 parent c0184ad commit ec139cb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

doc/Language/functions.pod6

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ C<MAIN> sub but the resulting exit code will always be zero (success).
985985
To provide an exit code different from 0,
986986
call L<exit|https://docs.perl6.org/routine/exit>.
987987
988+
#|(optional description for USAGE message)
988989
sub MAIN( Int :$length = 24,
989990
:file($data) where { .IO.f // die "file not found in $*CWD" } = 'file.dat',
990991
Bool :v(:$verbose) #`( either --verbose or -v ) )
@@ -1032,7 +1033,10 @@ If no multi candidate of C<MAIN> is found for the given command line
10321033
parameters, the sub C<USAGE> is called. If no such method is found,
10331034
the compiler will output a default generated usage message.
10341035
1035-
sub MAIN(Int $i){ say $i == 42 ?? 'answer' !! 'dunno' }
1036+
#|(is it the answer)
1037+
multi MAIN(Int $i){ say $i == 42 ?? 'answer' !! 'dunno' }
1038+
#|(divide two numbers)
1039+
multi MAIN($a, $b){ say $a/$b }
10361040
10371041
sub USAGE(){
10381042
print Q:c:to/EOH/;
@@ -1043,7 +1047,9 @@ the compiler will output a default generated usage message.
10431047
}
10441048
10451049
The default usage message is available inside C<sub USAGE> via read-only
1046-
C<$*USAGE> variable.
1050+
C<$*USAGE> variable. It will be generated based on available C<sub MAIN>
1051+
candidates and their parameters. You can specify additional extended
1052+
description for each candidate using C<#|(...)> Pod block to set L<WHY>.
10471053
10481054
=end pod
10491055

0 commit comments

Comments
 (0)