OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'src/arg_parser.dart'; | 9 import 'src/arg_parser.dart'; |
10 import 'src/arg_results.dart'; | 10 import 'src/arg_results.dart'; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 /// An unmodifiable view of all top-level commands defined for this runner. | 61 /// An unmodifiable view of all top-level commands defined for this runner. |
62 Map<String, Command> get commands => new UnmodifiableMapView(_commands); | 62 Map<String, Command> get commands => new UnmodifiableMapView(_commands); |
63 final _commands = <String, Command>{}; | 63 final _commands = <String, Command>{}; |
64 | 64 |
65 /// The top-level argument parser. | 65 /// The top-level argument parser. |
66 /// | 66 /// |
67 /// Global options should be registered with this parser; they'll end up | 67 /// Global options should be registered with this parser; they'll end up |
68 /// available via [Command.globalResults]. Commands should be registered with | 68 /// available via [Command.globalResults]. Commands should be registered with |
69 /// [addCommand] rather than directly on the parser. | 69 /// [addCommand] rather than directly on the parser. |
70 final argParser = new ArgParser(); | 70 ArgParser get argParser => _argParser; |
| 71 final _argParser = new ArgParser(); |
71 | 72 |
72 CommandRunner(this.executableName, this.description) { | 73 CommandRunner(this.executableName, this.description) { |
73 argParser.addFlag('help', | 74 argParser.addFlag('help', |
74 abbr: 'h', negatable: false, help: 'Print this usage information.'); | 75 abbr: 'h', negatable: false, help: 'Print this usage information.'); |
75 addCommand(new HelpCommand()); | 76 addCommand(new HelpCommand()); |
76 } | 77 } |
77 | 78 |
78 /// Prints the usage information for this runner. | 79 /// Prints the usage information for this runner. |
79 /// | 80 /// |
80 /// This is called internally by [run] and can be overridden by subclasses to | 81 /// This is called internally by [run] and can be overridden by subclasses to |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 /// This will be `null` until just before [Command.run] is called. | 243 /// This will be `null` until just before [Command.run] is called. |
243 ArgResults get argResults => _argResults; | 244 ArgResults get argResults => _argResults; |
244 ArgResults _argResults; | 245 ArgResults _argResults; |
245 | 246 |
246 /// The argument parser for this command. | 247 /// The argument parser for this command. |
247 /// | 248 /// |
248 /// Options for this command should be registered with this parser (often in | 249 /// Options for this command should be registered with this parser (often in |
249 /// the constructor); they'll end up available via [argResults]. Subcommands | 250 /// the constructor); they'll end up available via [argResults]. Subcommands |
250 /// should be registered with [addSubcommand] rather than directly on the | 251 /// should be registered with [addSubcommand] rather than directly on the |
251 /// parser. | 252 /// parser. |
252 final argParser = new ArgParser(); | 253 ArgParser get argParser => _argParser; |
| 254 final _argParser = new ArgParser(); |
253 | 255 |
254 /// Generates a string displaying usage information for this command. | 256 /// Generates a string displaying usage information for this command. |
255 /// | 257 /// |
256 /// This includes usage for the command's arguments as well as a list of | 258 /// This includes usage for the command's arguments as well as a list of |
257 /// subcommands, if there are any. | 259 /// subcommands, if there are any. |
258 String get usage => "$description\n\n$_usageWithoutDescription"; | 260 String get usage => "$description\n\n$_usageWithoutDescription"; |
259 | 261 |
260 /// An optional footer for [usage]. | 262 /// An optional footer for [usage]. |
261 /// | 263 /// |
262 /// If a subclass overrides this to return a string, it will automatically be | 264 /// If a subclass overrides this to return a string, it will automatically be |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 385 |
384 for (var line in lines.skip(1)) { | 386 for (var line in lines.skip(1)) { |
385 buffer.writeln(); | 387 buffer.writeln(); |
386 buffer.write(' ' * (length + 5)); | 388 buffer.write(' ' * (length + 5)); |
387 buffer.write(line); | 389 buffer.write(line); |
388 } | 390 } |
389 } | 391 } |
390 | 392 |
391 return buffer.toString(); | 393 return buffer.toString(); |
392 } | 394 } |
OLD | NEW |