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

Side by Side Diff: pkg/args/lib/src/arg_results.dart

Issue 796593004: Add an ArgResults.original getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/args/CHANGELOG.md ('k') | pkg/args/lib/src/parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.arg_results; 5 library args.src.arg_results;
6 6
7 import 'package:collection/wrappers.dart'; 7 import 'package:collection/wrappers.dart';
8 8
9 import 'arg_parser.dart'; 9 import 'arg_parser.dart';
10 10
11 /// Creates a new [ArgResults]. 11 /// Creates a new [ArgResults].
12 /// 12 ///
13 /// Since [ArgResults] doesn't have a public constructor, this lets [Parser] 13 /// Since [ArgResults] doesn't have a public constructor, this lets [Parser]
14 /// get to it. This function isn't exported to the public API of the package. 14 /// get to it. This function isn't exported to the public API of the package.
15 ArgResults newArgResults(ArgParser parser, Map<String, dynamic> parsed, 15 ArgResults newArgResults(ArgParser parser, Map<String, dynamic> parsed,
16 String name, ArgResults command, List<String> rest) { 16 String name, ArgResults command, List<String> rest,
17 return new ArgResults._(parser, parsed, name, command, rest); 17 List<String> arguments) {
18 return new ArgResults._(parser, parsed, name, command, rest, arguments);
18 } 19 }
19 20
20 /// The results of parsing a series of command line arguments using 21 /// The results of parsing a series of command line arguments using
21 /// [ArgParser.parse()]. 22 /// [ArgParser.parse()].
22 /// 23 ///
23 /// Includes the parsed options and any remaining unparsed command line 24 /// Includes the parsed options and any remaining unparsed command line
24 /// arguments. 25 /// arguments.
25 class ArgResults { 26 class ArgResults {
26 /// The [ArgParser] whose options were parsed for these results. 27 /// The [ArgParser] whose options were parsed for these results.
27 final ArgParser _parser; 28 final ArgParser _parser;
(...skipping 11 matching lines...) Expand all
39 final ArgResults command; 40 final ArgResults command;
40 41
41 /// The remaining command-line arguments that were not parsed as options or 42 /// The remaining command-line arguments that were not parsed as options or
42 /// flags. 43 /// flags.
43 /// 44 ///
44 /// If `--` was used to separate the options from the remaining arguments, 45 /// If `--` was used to separate the options from the remaining arguments,
45 /// it will not be included in this list unless parsing stopped before the 46 /// it will not be included in this list unless parsing stopped before the
46 /// `--` was reached. 47 /// `--` was reached.
47 final List<String> rest; 48 final List<String> rest;
48 49
50 /// The original list of arguments that were parsed.
51 final List<String> arguments;
52
49 /// Creates a new [ArgResults]. 53 /// Creates a new [ArgResults].
50 ArgResults._(this._parser, this._parsed, this.name, this.command, 54 ArgResults._(this._parser, this._parsed, this.name, this.command,
51 List<String> rest) 55 List<String> rest, List<String> arguments)
52 : this.rest = new UnmodifiableListView(rest); 56 : this.rest = new UnmodifiableListView(rest),
57 this.arguments = new UnmodifiableListView(arguments);
53 58
54 /// Gets the parsed command-line option named [name]. 59 /// Gets the parsed command-line option named [name].
55 operator [](String name) { 60 operator [](String name) {
56 if (!_parser.options.containsKey(name)) { 61 if (!_parser.options.containsKey(name)) {
57 throw new ArgumentError('Could not find an option named "$name".'); 62 throw new ArgumentError('Could not find an option named "$name".');
58 } 63 }
59 64
60 return _parser.options[name].getOrDefault(_parsed[name]); 65 return _parser.options[name].getOrDefault(_parsed[name]);
61 } 66 }
62 67
(...skipping 19 matching lines...) Expand all
82 /// value would be used instead. 87 /// value would be used instead.
83 bool wasParsed(String name) { 88 bool wasParsed(String name) {
84 var option = _parser.options[name]; 89 var option = _parser.options[name];
85 if (option == null) { 90 if (option == null) {
86 throw new ArgumentError('Could not find an option named "$name".'); 91 throw new ArgumentError('Could not find an option named "$name".');
87 } 92 }
88 93
89 return _parsed.containsKey(name); 94 return _parsed.containsKey(name);
90 } 95 }
91 } 96 }
OLDNEW
« no previous file with comments | « pkg/args/CHANGELOG.md ('k') | pkg/args/lib/src/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698