Handle nested subparsers #207
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 handles outputting for nested sub-parsers.
First we modify the load_sub_parsers iterator to check if any of the arguments are subparsers, and if so, recurse into that subparser and yield its values back too. (I am as skeptical of yielding from recursive generator functions as anyone :) If you have hundreds of levels of nested subparsers I guess this blows up ... but that seems impractical).
In _mk_sub_command, avoid adding subparsers so they don't show up as positional arguments (their Action has action.dest of "==SUPPRESS==" which looks wrong and they don't show up in cmd line help). The subparsers are listed in the usage-string, e.g.
test subparser [-h] [--foo FOO] {child_two} ...
In _build_opt_grp_title we are taking elements[:2] as the title text for the option group. This ends up cutting off the full title when you have nested subparsers. I have to admit I can't really determine why this is done, but it does not seem to affect any of the test cases and the output looks correct to me for nested subparsers, with the full command listed as the option title.