OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of cli; | 5 part of cli; |
6 | 6 |
7 // Splits a line into a list of string args. Each arg retains any | 7 // Splits a line into a list of string args. Each arg retains any |
8 // trailing whitespace so that we can reconstruct the original command | 8 // trailing whitespace so that we can reconstruct the original command |
9 // line from the pieces. | 9 // line from the pieces. |
10 List<String> _splitLine(String line) { | 10 List<String> _splitLine(String line) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return new Future.value(completions); | 163 return new Future.value(completions); |
164 } | 164 } |
165 | 165 |
166 // Runs a command. | 166 // Runs a command. |
167 Future runCommand(String line) { | 167 Future runCommand(String line) { |
168 _historyAdvance(line); | 168 _historyAdvance(line); |
169 var args = _splitLine(line); | 169 var args = _splitLine(line); |
170 var commands = _match(args, true); | 170 var commands = _match(args, true); |
171 if (commands.isEmpty) { | 171 if (commands.isEmpty) { |
172 // TODO(turnidge): Add a proper exception class for this. | 172 // TODO(turnidge): Add a proper exception class for this. |
173 return new Future.error('notfound'); | 173 return new Future.error('No such command'); |
174 } else if (commands.length == 1) { | 174 } else if (commands.length == 1) { |
175 return commands[0].run(args.sublist(commands[0]._depth)); | 175 return commands[0].run(args.sublist(commands[0]._depth)); |
176 } else { | 176 } else { |
177 // TODO(turnidge): Add a proper exception class for this. | 177 // TODO(turnidge): Add a proper exception class for this. |
178 return new Future.error('ambiguous'); | 178 return new Future.error('Ambiguous command'); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 // Find all matching commands. Useful for implementing help systems. | 182 // Find all matching commands. Useful for implementing help systems. |
183 List<Command> matchCommand(List<String> args, bool preferExact) { | 183 List<Command> matchCommand(List<String> args, bool preferExact) { |
184 if (args.isEmpty) { | 184 if (args.isEmpty) { |
185 // Adding an empty string to the end causes us to match all | 185 // Adding an empty string to the end causes us to match all |
186 // subcommands of the last command. | 186 // subcommands of the last command. |
187 args.add(''); | 187 args.add(''); |
188 } | 188 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if (_parent is RootCommand) { | 240 if (_parent is RootCommand) { |
241 return name; | 241 return name; |
242 } else { | 242 } else { |
243 Command parent = _parent; | 243 Command parent = _parent; |
244 return '${parent.fullName} $name'; | 244 return '${parent.fullName} $name'; |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 toString() => 'Command(${name})'; | 248 toString() => 'Command(${name})'; |
249 } | 249 } |
OLD | NEW |