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

Unified Diff: lib/src/arg_parser.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 | « example/test_runner.dart ('k') | lib/src/usage.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/arg_parser.dart
diff --git a/lib/src/arg_parser.dart b/lib/src/arg_parser.dart
index 49d6aa6bbf6dc4d7a965536049fd8c305e87006e..c32741df94e4115e82e8dedfa3ee75088f88aeb8 100644
--- a/lib/src/arg_parser.dart
+++ b/lib/src/arg_parser.dart
@@ -23,6 +23,10 @@ class ArgParser {
/// The commands that have been defined for this parser.
final Map<String, ArgParser> commands;
+ /// A list of the [Option]s in [options] intermingled with [String]
+ /// separators.
+ final _optionsAndSeparators = [];
+
/// Whether or not this parser parses options that appear after non-option
/// arguments.
final bool allowTrailingOptions;
@@ -110,9 +114,19 @@ class ArgParser {
}
}
- _options[name] = newOption(name, abbr, help, valueHelp, allowed,
+ var option = newOption(name, abbr, help, valueHelp, allowed,
allowedHelp, defaultsTo, callback, type,
negatable: negatable, splitCommas: splitCommas, hide: hide);
+ _options[name] = option;
+ _optionsAndSeparators.add(option);
+ }
+
+ /// Adds a separator line to the usage.
+ ///
+ /// In the usage text for the parser, this will appear between any options
+ /// added before this call and ones added after it.
+ void addSeparator(String text) {
+ _optionsAndSeparators.add(text);
}
/// Parses [args], a list of command-line arguments, matches them against the
@@ -124,12 +138,12 @@ class ArgParser {
///
/// This is basically the help text shown on the command line.
@Deprecated("Replaced with get usage. getUsage() will be removed in args 1.0")
- String getUsage() => new Usage(this).generate();
+ String getUsage() => usage;
/// Generates a string displaying usage information for the defined options.
///
/// This is basically the help text shown on the command line.
- String get usage => new Usage(this).generate();
+ String get usage => new Usage(_optionsAndSeparators).generate();
/// Get the default value for an option. Useful after parsing to test if the
/// user specified something other than the default.
« no previous file with comments | « example/test_runner.dart ('k') | lib/src/usage.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698