7
7
X < |command line arguments >
8
8
= head1 Command Line Interface - an overview
9
9
10
- The default command line interface of Perl 6 scripts consists of 3 parts:
10
+ The default command line interface of Perl 6 scripts consists of three parts:
11
11
12
12
= item 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
- interpretes these according to some policy, and creates a C < Capture > object
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
@@ -21,7 +21,7 @@ or installed using a module.
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
- of which responsible for some part of processing the given command line
24
+ of which is responsible for some part of processing the given command line
25
25
arguments.
26
26
27
27
= item creating / showing USAGE information if calling MAIN failed
@@ -38,7 +38,7 @@ X<|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
41
- the mainline of the script have been executed. No error will occur if there
41
+ the mainline of the script has been executed. No error will occur if there
42
42
is no MAIN sub: your script will then just have to do the work, such as
43
43
argument parsing, in the mainline of the script.
44
44
@@ -89,14 +89,14 @@ $ perl6 hello.p6 Liz
89
89
Hello Liz, how are you?
90
90
= end code
91
91
92
- Another way to do this, is to make sub MAIN a C < multi sub > :
92
+ Another way to do this is to make sub MAIN a C < multi sub > :
93
93
94
94
# inside file 'hello.p6'
95
95
multi sub MAIN() { say "Hello bashful, how are you?" }
96
96
multi sub MAIN($name) { say "Hello $name, how are you?" }
97
97
98
98
Which would give the same output as the examples above. Whether you should
99
- use either method to achieve the desired goal, is entirely up to you.
99
+ use either method to achieve the desired goal is entirely up to you.
100
100
101
101
A more complicated example using a single positional and multiple
102
102
named parameters:
@@ -141,7 +141,7 @@ Usage:
141
141
142
142
Although you don't have to do anything in your code to do this, it may still
143
143
be regarded as a bit terse. But there's an easy way to make that usage
144
- message better: by providing hints using pod features:
144
+ message better by providing hints using pod features:
145
145
146
146
# inside "frobnicate.p6"
147
147
sub MAIN(
@@ -282,7 +282,7 @@ C<#|(...)> Pod block to set L«C<WHY>|/routine/WHY».
282
282
283
283
= head1 Intercepting CLI argument parsing (2018.10, v6.d and later)
284
284
285
- You can replace / augment the default way of argument parsing by supplying a
285
+ You can replace or augment the default way of argument parsing by supplying a
286
286
C < ARGS-TO-CAPTURE > subroutine yourself, or by importing one from any of
287
287
the L < Getopt|https://modules.perl6.org/search/?q=getopt > modules available
288
288
in the ecosystem.
@@ -295,7 +295,7 @@ representing the C<MAIN> unit to be executed (so it can be introspected if
295
295
necessary) and an array with the arguments from the command line. It
296
296
should return a L < Capture|/type/Capture > object that should be used to
297
297
dispatch the C < MAIN > unit. A B < very > contrived example that will create
298
- a C < Capture > dependin on some keyword that was entered (which can be handy
298
+ a C < Capture > depending on some keyword that was entered (which can be handy
299
299
during testing of a command line interface of a script):
300
300
301
301
sub ARGS-TO-CAPTURE(&main, @args --> Capture) {
@@ -308,7 +308,7 @@ during testing of a command line interface of a script):
308
308
}
309
309
310
310
Note that the dynamic variable L < &*ARGS-TO-CAPTURE > is available to perform
311
- the default command line arguments to C < Capture > processing, so you don't
311
+ the default command line arguments to C < Capture > processing so you don't
312
312
have to reinvent the whole wheel if you don't want to.
313
313
314
314
X < |&*ARGS-TO-CAPTURE >
@@ -320,7 +320,7 @@ parameters as are expected of the custom C<ARGS-TO-CAPTURE> subroutine.
320
320
321
321
= head1 Intercepting usage message generation (2018.10, v6.d and later)
322
322
323
- You can replace / augment the default way of usage message generation
323
+ You can replace or augment the default way of usage message generation
324
324
(after a failed dispatch to MAIN) by supplying a C < GENERATE-USAGE > subroutine
325
325
yourself, or by importing one from any of the
326
326
L < Getopt|https://modules.perl6.org/search/?q=getopt > modules available in the
@@ -353,7 +353,7 @@ You can also use multi subroutine to create the same effect:
353
353
}
354
354
355
355
Note that the dynamic variable L < &*GENERATE-USAGE > is available to perform
356
- the default usage message generation, so you don't have to reinvent the
356
+ 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
X < |&*GENERATE-USAGE >
0 commit comments