Skip to content

Handle nested subparsers #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Conversation

ianw
Copy link
Contributor

@ianw ianw commented Dec 4, 2024

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.

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.
@ianw
Copy link
Contributor Author

ianw commented Dec 4, 2024

Screenshot 2024-12-04 at 13-11-56 test - CLI interface — Project name not set documentation

Above is the output I see for the included test case

@gaborbernat gaborbernat merged commit 724e596 into tox-dev:main Dec 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants