| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 for (var name in names) { | 91 for (var name in names) { |
| 92 _commands[name] = command; | 92 _commands[name] = command; |
| 93 argParser.addCommand(name, command.argParser); | 93 argParser.addCommand(name, command.argParser); |
| 94 } | 94 } |
| 95 command._runner = this; | 95 command._runner = this; |
| 96 } | 96 } |
| 97 | 97 |
| 98 /// Parses [args] and invokes [Command.run] on the chosen command. | 98 /// Parses [args] and invokes [Command.run] on the chosen command. |
| 99 /// | 99 /// |
| 100 /// This always returns a [Future] in case the command is asynchronous. The | 100 /// This always returns a [Future] in case the command is asynchronous. The |
| 101 /// [Future] will throw a [UsageError] if [args] was invalid. | 101 /// [Future] will throw a [UsageException] if [args] was invalid. |
| 102 Future run(Iterable<String> args) => | 102 Future run(Iterable<String> args) => |
| 103 new Future.sync(() => runCommand(parse(args))); | 103 new Future.sync(() => runCommand(parse(args))); |
| 104 | 104 |
| 105 /// Parses [args] and returns the result, converting a [FormatException] to a | 105 /// Parses [args] and returns the result, converting a [FormatException] to a |
| 106 /// [UsageException]. | 106 /// [UsageException]. |
| 107 /// | 107 /// |
| 108 /// This is notionally a protected method. It may be overridden or called from | 108 /// This is notionally a protected method. It may be overridden or called from |
| 109 /// subclasses, but it shouldn't be called externally. | 109 /// subclasses, but it shouldn't be called externally. |
| 110 ArgResults parse(Iterable<String> args) { | 110 ArgResults parse(Iterable<String> args) { |
| 111 try { | 111 try { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 for (var line in lines.skip(1)) { | 384 for (var line in lines.skip(1)) { |
| 385 buffer.writeln(); | 385 buffer.writeln(); |
| 386 buffer.write(' ' * (length + 5)); | 386 buffer.write(' ' * (length + 5)); |
| 387 buffer.write(line); | 387 buffer.write(line); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 return buffer.toString(); | 391 return buffer.toString(); |
| 392 } | 392 } |
| OLD | NEW |