Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgsResult should have a way to determine if the user actual set the value #16227

Closed
DartBot opened this issue Jan 20, 2014 · 9 comments
Closed
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 20, 2014

This issue was originally filed by Erik.G...@gmail.com


Currently there is no way to differentiate between the user specifying the default value and the user not specifying anything, both result in the default value being in ArgResults. This causes a problem when you have default values and multiple sources of configuration information that you'd like to merge. For example if you would like to have a default configuration that you to allow be overridden by environment variables and command line arguments, with command line arguments having the highest priority.

@kevmoo
Copy link
Member

kevmoo commented Jan 20, 2014

Added Area-Library, Library-Args, Triaged labels.

@lrhn
Copy link
Member

lrhn commented Jan 21, 2014

Removed Area-Library label.
Added Area-Pkg label.

@DartBot
Copy link
Author

DartBot commented Jan 21, 2014

This comment was originally written by @seaneagan


Interesting. Dart used to have an equivalent feature for function arguments, until it was removed by popular demand (issue #9097).

If the default value is calculated like that, then does it make sense to have an explicit default value? Seems like it might make more sense to just explain the default calculation in the help:, and leave null as the default value, in which case you can tell whether a value was specified since there is no way to pass null from the command line. However for flags, defaultsTo defaults to false, not null, so would need to do defaultsTo: null for that, haven't tested if that works.

@DartBot
Copy link
Author

DartBot commented Jan 29, 2014

This comment was originally written by Erik.Gri...@gmail.com


I like having default values for a nice out of the box experience. I ended creating a settings object that takes a map as a source and provides the default values if they're not in the map. Then I merge Platform.environment and ArgResults[] into the map provided to the settings object. There's a bit of friction as ArgResults doesn't implement Map or provide an accessor to a Map view, so I have to loop through the options rather than just using Map.addAll. Any thoughts on why ArgResults doesn't implement map or provide an accessor to a Map view? I think having ArgResults implement Map or provide an accessor to a Map view might make merging configuration sources cleaner.

@anders-sandholm
Copy link
Contributor

Removed Library-Args label.
Added Pkg-Args label.

@munificent
Copy link
Member

I like having default values for a nice out of the box experience.

Agreed. In particular, default values are shown in the usage information.

Any thoughts on why ArgResults doesn't implement map or provide an accessor to a Map view?

Args is super old so I think the map type was still in flux when I first wrote it. I'll follow up on the other bug for this.


Set owner to @munificent.
Removed Type-Defect label.
Added Type-Enhancement, Started labels.

@munificent
Copy link
Member

I just pushed arg 0.12.0, which adds a .wasParsed() method to ArgResults.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jul 18, 2014

This comment was originally written by Erik.Gr...@gmail.com


Excellent. Thank you!

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Jul 18, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/args#28.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants