rvesse / airline

Java annotation-based framework for parsing Git like command line structures with deep extensibility
https://rvesse.github.io/airline/
Apache License 2.0
128 stars 20 forks source link

Provide an option/argument defaulting mechanism #131

Open rvesse opened 8 months ago

rvesse commented 8 months ago

As seen in #49 there is a general need to support additional ways for users to supply default values to Airline based CLIs. Another common use case from my own $dayjob usage is taking defaults from environment variables. Currently doing this requires providing custom application specific solutions. It would be nice if Airline provided a standard plugin point for this that could then be customised by end users.

My rough idea is to add a new internal phase to the parsing process that would occur after all options and arguments have been passed BUT before we enforce restrictions final validation. The default value supplied would be injected into the list of parsed options/arguments as appropriate ONLY when that particular option/argument hadn't been supplied. Normal restrictions on that option/argument should still apply as usual.

The new DefaultsProvider interface would be pluggable allowing users to configure their desired one on their parser configuration. Likely we'd supply some basic implementations for configuration files (#49) and environment variables.