Add factory method on Application for customizing the Loader parsing cmd-line args #360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add capability to modify the the Loader used to parse cmd-lines used by
Application
class (currently theKVArgParseConfigLoader
class) without fully reimplementingApplication.parse_command_line()
method.Rationale
With the above customization it is easier to modify the argparse parser, which has been enabled by #322.
A case where the above is needed arrives in projects with multiple sub-cmds, where some cmd-names clash, and argparse "conflicts" occur (when adding the same option, twice).
While the argparse constructor offers the
conflict_handler='resolve'
strategy,and there exists anargparse
factory method on the Loder, there is no equivalent factory method on the Application for the Loader itself - that means that you cannot modify the former factory by switching Loader implementations, unless you re-implementApplication.parse_command_line()
, which is not trivial code.An alternative to this PR would be to add all
*argparse_args
and**argparse_kwds
onApplication
class, and pass them when constructing the Loader, which should then pass them toargparse
, but a) this violates blatantly the Demeter law adding dead weight for most cases, and b) being easier to override the Loader might be useful for other cases as well.