-
Notifications
You must be signed in to change notification settings - Fork 62
Introduce new typed ArgResults
flag(String)
, option(String)
, and multiOption(String)
methods
#248
Conversation
@@ -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]. | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// > [!Note]
/// > Callers should prefer using the more strongly typed methods - [flag] for
/// > flags, [option] for options, and [multiOption] for multi-options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
@@ -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]. | |||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
Hmm, this PR has introduced a bit of asymmetry in the API. With the new However, with the existing https://github.com/dart-lang/args/blob/master/lib/src/arg_parser.dart#L129C3-L136C42 So an ArgParser can be created that will always throw when you try and retrieve the flag value from the ArgResults. I could see a few resolutions here:
I'd lean towards option 2 above. |
I suppose folks who are broken by the change can move to checking |
Yeah, I ran across this when updating the dart cli to use these new methods. |
You could add something like |
I think I'm more inclined not add this in favor of keeping the undesirable pattern localized to where it is used. If code is doing something usual like a tri-state flag, it's OK for the code to also look unusual and need an extra If some project has strong opinions about the API they can hide that pattern behind an |
…d `multiOption(String)` methods (dart-archive/args#248) * introduce types methods to ArgResults * rename methods * updates * review feedback * reduce PR diffs * reduce PR diffs * review feedback * Update arg_results.dart
ArgResults
flag(String)
,option(String)
, andmultiOption(String)
methodsThis API lets people pull flags, options, and multi-options out of results objects without having to cast the values (e.g.,
results['param1'] as bool
,results['param2'] as String?
, ...). This is similar to the approach discussed in dart-lang/core#39.Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.