@@ -9,22 +9,22 @@ X<|command line arguments>
9
9
10
10
The default command line interface of Perl 6 scripts consists of three parts:
11
11
12
- = item Parsing the command line parameters into a L < capture|/type/Capture >
12
+ = head2 Parsing the command line parameters into a L < capture|/type/Capture >
13
13
14
14
This looks at the values in L < @*ARGS|/language/variables#index-entry-@*ARGS > ,
15
15
interprets these according to some policy, and creates a C < Capture > object
16
16
out of that. An alternative way of parsing may be provided by the developer
17
17
or installed using a module.
18
18
19
- = item Calling a provided MAIN subroutine using that capture
19
+ = head2 Calling a provided C < MAIN > subroutine using that capture
20
20
21
21
Standard L < multi dispatch|/language/functions#index-entry-declarator_multi-Multi-dispatch >
22
22
is used to call the MAIN subroutine with the generated C < Capture > object.
23
23
This means that your MAIN subroutine may be a C < multi sub > , each candidate
24
24
of which is responsible for some part of processing the given command line
25
25
arguments.
26
26
27
- = item Creating / showing usage information if calling MAIN failed
27
+ = item2 Creating / showing usage information if calling C < MAIN > failed
28
28
29
29
If multi dispatch failed, then the user of the script should be informed as
30
30
well as possible as to why it failed. By default, this is done by inspecting
@@ -34,7 +34,7 @@ was specified). An alternative way of generating the usage information may
34
34
be provided by the developer or installed using a module.
35
35
36
36
X < |MAIN >
37
- = head2 sub MAIN
37
+ = head1 sub MAIN
38
38
39
39
The sub with the special name C < MAIN > will be executed after all relevant entry
40
40
phasers (C < BEGIN > , C < CHECK > , C < INIT > , C < PRE > , C < ENTER > ) have been run and
@@ -169,7 +169,7 @@ Usage:
169
169
= end code
170
170
171
171
X < |%*SUB-MAIN-OPTS >
172
- = head3 %*SUB-MAIN-OPTS
172
+ = head2 %*SUB-MAIN-OPTS
173
173
174
174
It's possible to alter how arguments are processed before they're passed
175
175
to C < sub MAIN {} > by setting options in the C < %*SUB-MAIN-OPTS > hash. Due to
@@ -188,7 +188,7 @@ For instance:
188
188
Available options are:
189
189
190
190
X < |named-anywhere >
191
- = head4 named-anywhere
191
+ = head3 named-anywhere
192
192
193
193
By default, named arguments passed to the program (i.e., C < MAIN > )
194
194
cannot appear after any positional argument. However, if
@@ -201,7 +201,7 @@ $ perl6 example.p6 1 --c=2 3 --d=4
201
201
= end code
202
202
203
203
X < |hidden-from-USAGE >
204
- = head3 is hidden-from-USAGE
204
+ = head2 is hidden-from-USAGE
205
205
206
206
Sometimes you want to exclude a C < MAIN > candidate from being shown in any
207
207
automatically generated usage message. This can be achieved by adding
@@ -238,7 +238,7 @@ Usage:
238
238
Which, although technically correct, doesn't read as well.
239
239
240
240
X < |declarator,unit (MAIN) >
241
- = head2 Unit-scoped definition of C < MAIN >
241
+ = head1 Unit-scoped definition of C < MAIN >
242
242
243
243
If the entire program body resides within C < MAIN > , you can use the C < unit >
244
244
declarator as follows (adapting an earlier example):
@@ -295,11 +295,11 @@ in the ecosystem.
295
295
X < |ARGS-TO-CAPTURE >
296
296
= head2 sub ARGS-TO-CAPTURE
297
297
298
- The C < ARGS-TO-CAPTURE > subroutine should accept two parameters: a L < Callable|/type/Callable >
299
- representing the C < MAIN > unit to be executed (so it can be introspected if
300
- necessary) and an array with the arguments from the command line. It
301
- should return a L < Capture|/type/Capture > object that will be used to
302
- dispatch the C < MAIN > unit. A B < very > contrived example that will create
298
+ The C < ARGS-TO-CAPTURE > subroutine should accept two parameters: a
299
+ L < Callable|/type/Callable > representing the C < MAIN > unit to be executed (so it
300
+ can be introspected if necessary) and an array with the arguments from the
301
+ command line. It should return a L < Capture|/type/Capture > object that will be
302
+ used to dispatch the C < MAIN > unit. A B < very > contrived example that will create
303
303
a C < Capture > depending on some keyword that was entered (which can be handy
304
304
during testing of a command line interface of a script):
305
305
@@ -312,9 +312,9 @@ during testing of a command line interface of a script):
312
312
!! &*ARGS-TO-CAPTURE(&main, @args)
313
313
}
314
314
315
- Note that the dynamic variable L < C < &*ARGS-TO-CAPTURE > |/language/variables#&*ARGS-TO-CAPTURE >
316
- is available to perform
317
- the default command line arguments to C < Capture > processing so you don't
315
+ Note that the dynamic variable
316
+ L < C < &*ARGS-TO-CAPTURE > |/language/variables#&*ARGS-TO-CAPTURE > is available to
317
+ perform the default command line arguments to C < Capture > processing so you don't
318
318
have to reinvent the whole wheel if you don't want to.
319
319
320
320
= head1 Intercepting usage message generation (2018.10, v6.d and later)
@@ -351,9 +351,9 @@ You can also use multi subroutines to create the same effect:
351
351
&*GENERATE-USAGE(&main, |capture)
352
352
}
353
353
354
- Note that the dynamic variable L < C < &*GENERATE-USAGE > |/language/variables#&*GENERATE-USAGE >
355
- is available to perform
356
- the default usage message generation so you don't have to reinvent the
354
+ Note that the dynamic variable
355
+ L < C < &*GENERATE-USAGE > |/language/variables#&*GENERATE-USAGE > is available to
356
+ perform the default usage message generation so you don't have to reinvent the
357
357
whole wheel if you don't want to.
358
358
359
359
= head1 Intercepting MAIN calling (before 2018.10, v6.e)
0 commit comments