| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 var prefix = _concatArgs(args, _depth); | 109 var prefix = _concatArgs(args, _depth); |
| 110 return completions.map((str) => '${prefix}${str}').toList(); | 110 return completions.map((str) => '${prefix}${str}').toList(); |
| 111 }); | 111 }); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } | 114 } |
| 115 | 115 |
| 116 // The root of a tree of commands. | 116 // The root of a tree of commands. |
| 117 class RootCommand extends _CommandBase { | 117 class RootCommand extends _CommandBase { |
| 118 RootCommand(List<Command> children) : super(children); | 118 RootCommand(List<Command> children, [List<String> history]) |
| 119 : this._(children, history ?? ['']); |
| 120 |
| 121 RootCommand._(List<Command> children, List<String> history) |
| 122 : history = history, |
| 123 historyPos = history.length - 1, |
| 124 super(children); |
| 119 | 125 |
| 120 // Provides a list of possible completions for a line of text. | 126 // Provides a list of possible completions for a line of text. |
| 121 Future<List<String>> completeCommand(String line) { | 127 Future<List<String>> completeCommand(String line) { |
| 122 var args = _splitLine(line); | 128 var args = _splitLine(line); |
| 123 bool showAll = line.endsWith(' ') || args.isEmpty; | 129 bool showAll = line.endsWith(' ') || args.isEmpty; |
| 124 if (showAll) { | 130 if (showAll) { |
| 125 // Adding an empty string to the end causes us to match all | 131 // Adding an empty string to the end causes us to match all |
| 126 // subcommands of the last command. | 132 // subcommands of the last command. |
| 127 args.add(''); | 133 args.add(''); |
| 128 } | 134 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (args.isEmpty) { | 190 if (args.isEmpty) { |
| 185 // Adding an empty string to the end causes us to match all | 191 // Adding an empty string to the end causes us to match all |
| 186 // subcommands of the last command. | 192 // subcommands of the last command. |
| 187 args.add(''); | 193 args.add(''); |
| 188 } | 194 } |
| 189 return _match(args, preferExact); | 195 return _match(args, preferExact); |
| 190 } | 196 } |
| 191 | 197 |
| 192 // Command line history always contains one slot to hold the current | 198 // Command line history always contains one slot to hold the current |
| 193 // line, so we start off with one entry. | 199 // line, so we start off with one entry. |
| 194 List<String> history = ['']; | 200 List<String> history; |
| 195 int historyPos = 0; | 201 int historyPos; |
| 196 | 202 |
| 197 String historyPrev(String line) { | 203 String historyPrev(String line) { |
| 198 if (historyPos == 0) { | 204 if (historyPos == 0) { |
| 199 return line; | 205 return line; |
| 200 } | 206 } |
| 201 history[historyPos] = line; | 207 history[historyPos] = line; |
| 202 historyPos--; | 208 historyPos--; |
| 203 return history[historyPos]; | 209 return history[historyPos]; |
| 204 } | 210 } |
| 205 | 211 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (_parent is RootCommand) { | 246 if (_parent is RootCommand) { |
| 241 return name; | 247 return name; |
| 242 } else { | 248 } else { |
| 243 Command parent = _parent; | 249 Command parent = _parent; |
| 244 return '${parent.fullName} $name'; | 250 return '${parent.fullName} $name'; |
| 245 } | 251 } |
| 246 } | 252 } |
| 247 | 253 |
| 248 toString() => 'Command(${name})'; | 254 toString() => 'Command(${name})'; |
| 249 } | 255 } |
| OLD | NEW |