-
Notifications
You must be signed in to change notification settings - Fork 60
Introduce new typed ArgResults flag(String), option(String), and multiOption(String) methods
#248
Changes from 4 commits
5f61af0
493b82f
b6f0561
60c0856
bcf160a
dcd993d
04d42b1
4b5737f
dee2668
8befc1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ ArgResults newArgResults( | |
| } | ||
|
|
||
| /// The results of parsing a series of command line arguments using | ||
| /// [ArgParser.parse()]. | ||
| /// [ArgParser.parse]. | ||
| /// | ||
| /// Includes the parsed options and any remaining unparsed command line | ||
| /// arguments. | ||
|
|
@@ -57,7 +57,7 @@ class ArgResults { | |
| : rest = UnmodifiableListView(rest), | ||
| arguments = UnmodifiableListView(arguments); | ||
|
|
||
| /// Returns the parsed ore default command-line option named [name]. | ||
| /// Returns the parsed or default command-line option named [name]. | ||
| /// | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we deprecate this? Or at least mention the new alternatives here in the dartdoc?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't mark it deprecated (or at least not yet), but I like the idea of having the doc comment here point to the new better methods.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was a little hesitant about deprecating it given that essentially every user of this package will get deprecation messages. Updating the docs here make sense.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| /// [name] must be a valid option name in the parser. | ||
| dynamic operator [](String name) { | ||
|
|
@@ -73,6 +73,51 @@ class ArgResults { | |
| return option.valueOrDefault(_parsed[name]); | ||
| } | ||
|
|
||
| /// Returns the parsed or default command-line flag named [name]. | ||
| /// | ||
| /// [name] must be a valid flag name in the parser. | ||
| bool flag(String name) { | ||
| if (!_parser.options.containsKey(name)) { | ||
| throw ArgumentError('Could not find an option named "$name".'); | ||
| } | ||
|
|
||
| var option = _parser.options[name]!; | ||
devoncarew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!option.isFlag) { | ||
| throw ArgumentError('"$name" is not a flag.'); | ||
| } | ||
| return option.valueOrDefault(_parsed[name]) as bool; | ||
| } | ||
|
|
||
| /// Returns the parsed or default command-line option named [name]. | ||
| /// | ||
| /// [name] must be a valid option name in the parser. | ||
| String? option(String name) { | ||
| if (!_parser.options.containsKey(name)) { | ||
| throw ArgumentError('Could not find an option named "$name".'); | ||
| } | ||
|
|
||
| var option = _parser.options[name]!; | ||
| if (!option.isSingle) { | ||
| throw ArgumentError('"$name" is not an option.'); | ||
| } | ||
| return option.valueOrDefault(_parsed[name]) as String?; | ||
| } | ||
|
|
||
| /// Returns the list of parsed (or default) command-line options for [name]. | ||
| /// | ||
| /// [name] must be a valid option name in the parser. | ||
| List<String> multiOption(String name) { | ||
| if (!_parser.options.containsKey(name)) { | ||
| throw ArgumentError('Could not find an option named "$name".'); | ||
| } | ||
|
|
||
| var option = _parser.options[name]!; | ||
| if (!option.isMultiple) { | ||
| throw ArgumentError('"$name" is not a multi-option.'); | ||
| } | ||
| return option.valueOrDefault(_parsed[name]) as List<String>; | ||
| } | ||
|
|
||
| /// The names of the available options. | ||
| /// | ||
| /// Includes the options whose values were parsed or that have defaults. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.