Skip to content
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

Subcommands stripped in help screen when using option groups #99

Closed
kdeldycke opened this issue Oct 14, 2021 · 4 comments
Closed

Subcommands stripped in help screen when using option groups #99

kdeldycke opened this issue Oct 14, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@kdeldycke
Copy link
Contributor

While playing with option groups (see #98), I stumbled upon a bug when I tried to use them in combination with subcommand sections, which got lost in the process.

See for instance this CLI definition:

import click
from cloup import Group, OptionGroupMixin, command, group, option, option_group

class GroupWithOptionGroup(OptionGroupMixin, Group):
    pass

@group(cls=GroupWithOptionGroup)
@option_group(
    "Group 1",
    option("--opt1"),
    option("--opt2"),
)
@option_group(
    "Group 2",
    option("--opt1"),
    option("--opt2"),
)
@option("--config")
@click.version_option()
@click.help_option("-h", "--help")
@click.pass_context
def cli(ctx):
    pass

@command()
@click.pass_context
def command1(ctx):
    pass

@command()
@click.pass_context
def command2(ctx):
    pass

@command()
@click.pass_context
def command3(ctx):
    pass

@command()
@click.pass_context
def command4(ctx):
    pass

cli.section("Subcommand group #1", command1, command2)
cli.section("Extra commands", command3, command4)

if __name__ == "__main__":
    cli()

And here the help screen it produces:

$ python ./cloup_subcommand_sections.py
Usage: cloup_subcommand_sections.py [OPTIONS] COMMAND [ARGS]...

Group 1:
  --opt1 TEXT
  --opt2 TEXT

Group 2:
  --opt1 TEXT
  --opt2 TEXT

Other options:
  --config TEXT
  --version      Show the version and exit.
  -h, --help     Show this message and exit.

See how subcommands are nowhere to be found? This has been qualified as a bug by @janluke.

@kdeldycke kdeldycke added the bug Something isn't working label Oct 14, 2021
@janluke
Copy link
Owner

janluke commented Oct 14, 2021

Oh, that's because in click, it's format_options that calls format_commands 🤦‍♂️ .

@janluke
Copy link
Owner

janluke commented Oct 14, 2021

Fixed and released with v0.12.1 :)

@kdeldycke
Copy link
Contributor Author

Thanks @janluke for the fix! That was fast!

I was just able to use option groups and subcommand section in my project: kdeldycke/meta-package-manager@05bb603

@janluke
Copy link
Owner

janluke commented Oct 15, 2021

You're welcome! It was an easy fix :) You were fast too in using it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants