Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library args.src.usage; | 5 library args.src.usage; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import '../args.dart'; | 9 import '../args.dart'; |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 55 |
| 56 Usage(this.args); | 56 Usage(this.args); |
| 57 | 57 |
| 58 /// Generates a string displaying usage information for the defined options. | 58 /// Generates a string displaying usage information for the defined options. |
| 59 /// This is basically the help text shown on the command line. | 59 /// This is basically the help text shown on the command line. |
| 60 String generate() { | 60 String generate() { |
| 61 buffer = new StringBuffer(); | 61 buffer = new StringBuffer(); |
| 62 | 62 |
| 63 calculateColumnWidths(); | 63 calculateColumnWidths(); |
| 64 | 64 |
| 65 args.options.forEach((name, option) { | 65 for (var optionOrSeparator in args.optionsAndSeparators) { |
| 66 if (option.hide) return; | 66 if (optionOrSeparator is String) { |
| 67 // Ensure that there's always a blank line before a separator. | |
| 68 if (buffer.isNotEmpty) buffer.write("\n\n"); | |
| 69 buffer.write(optionOrSeparator); | |
| 70 newlinesNeeded = 1; | |
| 71 continue; | |
| 72 } | |
| 73 | |
| 74 var option = optionOrSeparator; | |
|
Bob Nystrom
2015/05/21 16:43:16
Do you need an "as Option" here?
nweiz
2015/05/21 19:22:27
The analyzer infers it as dynamic, so it doesn't p
Bob Nystrom
2015/05/21 19:42:27
Yeah, I think so.
nweiz
2015/05/21 19:52:37
Done.
| |
| 75 if (option.hide) continue; | |
| 67 | 76 |
| 68 write(0, getAbbreviation(option)); | 77 write(0, getAbbreviation(option)); |
| 69 write(1, getLongOption(option)); | 78 write(1, getLongOption(option)); |
| 70 | 79 |
| 71 if (option.help != null) write(2, option.help); | 80 if (option.help != null) write(2, option.help); |
| 72 | 81 |
| 73 if (option.allowedHelp != null) { | 82 if (option.allowedHelp != null) { |
| 74 var allowedNames = option.allowedHelp.keys.toList(growable: false); | 83 var allowedNames = option.allowedHelp.keys.toList(growable: false); |
| 75 allowedNames.sort(); | 84 allowedNames.sort(); |
| 76 newline(); | 85 newline(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 87 } else if (!option.isFlag) { | 96 } else if (!option.isFlag) { |
| 88 write(2, '(defaults to "${option.defaultValue}")'); | 97 write(2, '(defaults to "${option.defaultValue}")'); |
| 89 } | 98 } |
| 90 } | 99 } |
| 91 | 100 |
| 92 // If any given option displays more than one line of text on the right | 101 // If any given option displays more than one line of text on the right |
| 93 // column (i.e. help, default value, allowed options, etc.) then put a | 102 // column (i.e. help, default value, allowed options, etc.) then put a |
| 94 // blank line after it. This gives space where it's useful while still | 103 // blank line after it. This gives space where it's useful while still |
| 95 // keeping simple one-line options clumped together. | 104 // keeping simple one-line options clumped together. |
| 96 if (numHelpLines > 1) newline(); | 105 if (numHelpLines > 1) newline(); |
| 97 }); | 106 } |
| 98 | 107 |
| 99 return buffer.toString(); | 108 return buffer.toString(); |
| 100 } | 109 } |
| 101 | 110 |
| 102 String getAbbreviation(Option option) { | 111 String getAbbreviation(Option option) { |
| 103 if (option.abbreviation != null) { | 112 if (option.abbreviation != null) { |
| 104 return '-${option.abbreviation}, '; | 113 return '-${option.abbreviation}, '; |
| 105 } else { | 114 } else { |
| 106 return ''; | 115 return ''; |
| 107 } | 116 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 String padRight(String source, int length) { | 243 String padRight(String source, int length) { |
| 235 final result = new StringBuffer(); | 244 final result = new StringBuffer(); |
| 236 result.write(source); | 245 result.write(source); |
| 237 | 246 |
| 238 while (result.length < length) { | 247 while (result.length < length) { |
| 239 result.write(' '); | 248 result.write(' '); |
| 240 } | 249 } |
| 241 | 250 |
| 242 return result.toString(); | 251 return result.toString(); |
| 243 } | 252 } |
| OLD | NEW |