Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Unified Diff: lib/src/usage.dart

Issue 1145413002: Add support for separators. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Code review changes Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/arg_parser.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/usage.dart
diff --git a/lib/src/usage.dart b/lib/src/usage.dart
index 11be54b38983900ea14ddf0c9223bcb20b2a6923..177a810b1efc2af1807a330b3b74eedd30390aa6 100644
--- a/lib/src/usage.dart
+++ b/lib/src/usage.dart
@@ -22,8 +22,8 @@ import '../args.dart';
class Usage {
static const NUM_COLUMNS = 3; // Abbreviation, long name, help.
- /// The parser this is generating usage for.
- final ArgParser args;
+ /// A list of the [Option]s intermingled with [String] separators.
+ final List optionsAndSeparators;
/// The working buffer for the generated usage text.
StringBuffer buffer;
@@ -53,7 +53,7 @@ class Usage {
/// content.
int newlinesNeeded = 0;
- Usage(this.args);
+ Usage(this.optionsAndSeparators);
/// Generates a string displaying usage information for the defined options.
/// This is basically the help text shown on the command line.
@@ -62,8 +62,17 @@ class Usage {
calculateColumnWidths();
- args.options.forEach((name, option) {
- if (option.hide) return;
+ for (var optionOrSeparator in optionsAndSeparators) {
+ if (optionOrSeparator is String) {
+ // Ensure that there's always a blank line before a separator.
+ if (buffer.isNotEmpty) buffer.write("\n\n");
+ buffer.write(optionOrSeparator);
+ newlinesNeeded = 1;
+ continue;
+ }
+
+ var option = optionOrSeparator as Option;
+ if (option.hide) continue;
write(0, getAbbreviation(option));
write(1, getLongOption(option));
@@ -94,7 +103,7 @@ class Usage {
// blank line after it. This gives space where it's useful while still
// keeping simple one-line options clumped together.
if (numHelpLines > 1) newline();
- });
+ }
return buffer.toString();
}
@@ -127,8 +136,9 @@ class Usage {
void calculateColumnWidths() {
int abbr = 0;
int title = 0;
- args.options.forEach((name, option) {
- if (option.hide) return;
+ for (var option in optionsAndSeparators) {
+ if (option is! Option) continue;
+ if (option.hide) continue;
// Make room in the first column if there are abbreviations.
abbr = max(abbr, getAbbreviation(option).length);
@@ -142,7 +152,7 @@ class Usage {
title = max(title, getAllowedTitle(allowed).length);
}
}
- });
+ }
// Leave a gutter between the columns.
title += 4;
« no previous file with comments | « lib/src/arg_parser.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698