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

Unified Diff: pkg/args/lib/src/arg_parser.dart

Issue 383913003: Add .wasParsed() to ArgResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove "-dev". Created 6 years, 5 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 | « pkg/args/lib/args.dart ('k') | pkg/args/lib/src/arg_results.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/args/lib/src/arg_parser.dart
diff --git a/pkg/args/lib/args.dart b/pkg/args/lib/src/arg_parser.dart
similarity index 69%
copy from pkg/args/lib/args.dart
copy to pkg/args/lib/src/arg_parser.dart
index ec40958991bc5a1a497cd26a652a0ead28016051..b1ee6280200885e982941823e3fa57b9aaa40659 100644
--- a/pkg/args/lib/args.dart
+++ b/pkg/args/lib/src/arg_parser.dart
@@ -1,15 +1,15 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library args;
+library args.src.arg_parser;
import 'package:collection/wrappers.dart';
-import 'src/parser.dart';
-import 'src/usage.dart';
-import 'src/options.dart';
-export 'src/options.dart';
+import 'arg_results.dart';
+import 'option.dart';
+import 'parser.dart';
+import 'usage.dart';
/// A class for taking a list of raw command line arguments and parsing out
/// options and flags from them.
@@ -69,7 +69,7 @@ class ArgParser {
void addFlag(String name, {String abbr, String help, bool defaultsTo: false,
bool negatable: true, void callback(bool value), bool hide: false}) {
_addOption(name, abbr, help, null, null, null, defaultsTo, callback,
- isFlag: true, negatable: negatable, hide: hide);
+ OptionType.FLAG, negatable: negatable, hide: hide);
}
/// Defines a value-taking option. Throws an [ArgumentError] if:
@@ -80,14 +80,14 @@ class ArgParser {
List<String> allowed, Map<String, String> allowedHelp, String defaultsTo,
void callback(value), bool allowMultiple: false, bool hide: false}) {
_addOption(name, abbr, help, valueHelp, allowed, allowedHelp, defaultsTo,
- callback, isFlag: false, allowMultiple: allowMultiple,
+ callback, allowMultiple ? OptionType.MULTIPLE : OptionType.SINGLE,
hide: hide);
}
void _addOption(String name, String abbr, String help, String valueHelp,
List<String> allowed, Map<String, String> allowedHelp, defaultsTo,
- void callback(value), {bool isFlag, bool negatable: false,
- bool allowMultiple: false, bool hide: false}) {
+ void callback(value), OptionType type, {bool negatable: false,
+ bool hide: false}) {
// Make sure the name isn't in use.
if (_options.containsKey(name)) {
throw new ArgumentError('Duplicate option "$name".');
@@ -102,9 +102,9 @@ class ArgParser {
}
}
- _options[name] = new Option(name, abbr, help, valueHelp, allowed,
- allowedHelp, defaultsTo, callback, isFlag: isFlag, negatable: negatable,
- allowMultiple: allowMultiple, hide: hide);
+ _options[name] = newOption(name, abbr, help, valueHelp, allowed,
+ allowedHelp, defaultsTo, callback, type, negatable: negatable,
+ hide: hide);
}
/// Parses [args], a list of command-line arguments, matches them against the
@@ -133,47 +133,3 @@ class ArgParser {
orElse: () => null);
}
}
-
-/// The results of parsing a series of command line arguments using
-/// [ArgParser.parse()].
-///
-/// Includes the parsed options and any remaining unparsed command line
-/// arguments.
-class ArgResults {
- final Map<String, dynamic> _options;
-
- /// If these are the results for parsing a command's options, this will be the
- /// name of the command. For top-level results, this returns `null`.
- final String name;
-
- /// The command that was selected, or `null` if none was.
- ///
- /// This will contain the options that were selected for that command.
- final ArgResults command;
-
- /// The remaining command-line arguments that were not parsed as options or
- /// flags.
- ///
- /// If `--` was used to separate the options from the remaining arguments,
- /// it will not be included in this list unless parsing stopped before the
- /// `--` was reached.
- final List<String> rest;
-
- /// Creates a new [ArgResults].
- ArgResults(this._options, this.name, this.command, List<String> rest)
- : this.rest = new UnmodifiableListView(rest);
-
- /// Gets the parsed command-line option named [name].
- operator [](String name) {
- if (!_options.containsKey(name)) {
- throw new ArgumentError(
- 'Could not find an option named "$name".');
- }
-
- return _options[name];
- }
-
- /// Get the names of the options as an [Iterable].
- Iterable<String> get options => _options.keys;
-}
-
« no previous file with comments | « pkg/args/lib/args.dart ('k') | pkg/args/lib/src/arg_results.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698