containertool: Don't set environment-variable defaults in parser #117
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.
Motivation
Many
containertool
options have default values set by environment variables.This pattern is quite convenient, but there are some drawbacks. For example:
--help
output: for some options, such as default base image, this is desirable, but for others, such as credentials, it is not.Some options do not fit this pattern well. For instance,
containertool
tries to detect the architecture of the executable it is packaging so it can try to choose a compatible base image.The path to the executable is an option which is parsed by the argument parser. It is not available when the parser sets up default argument values, so it must be handled after the arguments have been parsed, overwriting whatever the parser had set. This means that option handling for this flag is split into two different places, which invites bugs.
Future changes to
containertool
's configuration, such as supporting a configuration file on disk, add further complications.Modifications
run()
functionResult
No functional change, but maintenance and future enhancement become easier.
Test Plan
All existing tests continue to pass.
Handling defaults in this way allows future PRs to add unit or integration tests which exercise argument parsing.