OLD | NEW |
1 Parses raw command-line arguments into a set of options and values. | 1 Parses raw command-line arguments into a set of options and values. |
2 | 2 |
3 This library supports [GNU][] and [POSIX][] style options, and it works | 3 This library supports [GNU][] and [POSIX][] style options, and it works |
4 in both server-side and client-side apps. | 4 in both server-side and client-side apps. |
5 | 5 |
6 ## Defining options | 6 ## Defining options |
7 | 7 |
8 First create an [ArgParser][]: | 8 First create an [ArgParser][]: |
9 | 9 |
10 var parser = new ArgParser(); | 10 var parser = new ArgParser(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 option can occur multiple times, and the `parse()` method returns a list of | 182 option can occur multiple times, and the `parse()` method returns a list of |
183 values: | 183 values: |
184 | 184 |
185 ```dart | 185 ```dart |
186 var parser = new ArgParser(); | 186 var parser = new ArgParser(); |
187 parser.addOption('mode', allowMultiple: true); | 187 parser.addOption('mode', allowMultiple: true); |
188 var results = parser.parse(['--mode', 'on', '--mode', 'off']); | 188 var results = parser.parse(['--mode', 'on', '--mode', 'off']); |
189 print(results['mode']); // prints '[on, off]' | 189 print(results['mode']); // prints '[on, off]' |
190 ``` | 190 ``` |
191 | 191 |
| 192 By default, values for a multi-valued option may also be separated with commas: |
| 193 |
| 194 ```dart |
| 195 var parser = new ArgParser(); |
| 196 parser.addOption('mode', allowMultiple: true); |
| 197 var results = parser.parse(['--mode', 'on,off']); |
| 198 print(results['mode']); // prints '[on, off]' |
| 199 ``` |
| 200 |
| 201 This can be disabled by passing `splitCommas: false`. |
| 202 |
192 ## Defining commands ## | 203 ## Defining commands ## |
193 | 204 |
194 In addition to *options*, you can also define *commands*. A command is a named | 205 In addition to *options*, you can also define *commands*. A command is a named |
195 argument that has its own set of options. For example, consider this shell | 206 argument that has its own set of options. For example, consider this shell |
196 command: | 207 command: |
197 | 208 |
198 ``` | 209 ``` |
199 $ git commit -a | 210 $ git commit -a |
200 ``` | 211 ``` |
201 | 212 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 [Command]: http://www.dartdocs.org/documentation/args/latest/index.html#args/arg
s.Command | 390 [Command]: http://www.dartdocs.org/documentation/args/latest/index.html#args/arg
s.Command |
380 [UsageError]: http://www.dartdocs.org/documentation/args/latest/index.html#args/
args.UsageError | 391 [UsageError]: http://www.dartdocs.org/documentation/args/latest/index.html#args/
args.UsageError |
381 [addOption]: http://www.dartdocs.org/documentation/args/latest/index.html#args/a
rgs.ArgParser@id_addOption | 392 [addOption]: http://www.dartdocs.org/documentation/args/latest/index.html#args/a
rgs.ArgParser@id_addOption |
382 [addFlag]: http://www.dartdocs.org/documentation/args/latest/index.html#args/arg
s.ArgParser@id_addFlag | 393 [addFlag]: http://www.dartdocs.org/documentation/args/latest/index.html#args/arg
s.ArgParser@id_addFlag |
383 [parse]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.
ArgParser@id_parse | 394 [parse]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.
ArgParser@id_parse |
384 [rest]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.A
rgResults@id_rest | 395 [rest]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.A
rgResults@id_rest |
385 [addCommand]: http://www.dartdocs.org/documentation/args/latest/index.html#args/
args.ArgParser@id_addCommand | 396 [addCommand]: http://www.dartdocs.org/documentation/args/latest/index.html#args/
args.ArgParser@id_addCommand |
386 [getUsage]: http://www.dartdocs.org/documentation/args/latest/index.html#args/ar
gs.ArgParser@id_getUsage | 397 [getUsage]: http://www.dartdocs.org/documentation/args/latest/index.html#args/ar
gs.ArgParser@id_getUsage |
387 [addSubcommand]: http://www.dartdocs.org/documentation/args/latest/index.html#ar
gs/args.Command@id_addSubcommand | 398 [addSubcommand]: http://www.dartdocs.org/documentation/args/latest/index.html#ar
gs/args.Command@id_addSubcommand |
388 [run]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.Co
mmand@id_run | 399 [run]: http://www.dartdocs.org/documentation/args/latest/index.html#args/args.Co
mmand@id_run |
OLD | NEW |