Introduce argparse for argument parsing #7
Merged
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.
This addresses #5. I am not 100% happy with the restructuring, but I tried to not change the user interface and keep it as is.
The fact that passing no argument acts as it's own subcommand makes it hard to handle the argument parsing in a uniform way.
The proposed implementation uses "subparsers" to handle the subcommand, as this allows to make the positional arguments optional (which wouldn't be allowed otherwise without making them flags starting with "--"). This has the benefit however, that e.g.
mrefilename
can be cleanly handled as an argument to a subcommand so that it is possible to read it's documentation when callingpumla update --help
.The "hacky" part, which is providing a default attribute
func
for each subcommand and executing it after parsing is actually taken from the official documentation. It just get's a little more verbose, because we need to handle the "no argument provided" usecase.The final output of calling
pumla --help
now looks like this: