ewels / rich-click

Format click help output nicely with rich.
https://ewels.github.io/rich-click/
MIT License
583 stars 33 forks source link

Easier way to define option and command groups #157

Open dwreeves opened 5 months ago

dwreeves commented 5 months ago

Overview

I think the option and command group API is a little clunky and could be easier to use.

The API was designed with the global config in mind. Since version 1.7, however, the global config is no longer the only way to define config; the API has moved closer to the definition of commands.


Brain Dump

I don't know the best way to proceed here, but here's one idea:

import rich_click as click

@click.group
@click.option("--option1", option_group_name="foo")
@click.option("--option2", option_group_name="foo")
@click.option("--option3")
@click.rich_config(help_config=click.RichHelpConfiguration(
    option_groups=[
        {
            "name": "foo",
            "table_styles": {
                "show_lines": False
            }
        },
        {
            "name": "bar",
            "options": ["--option3"]
            "table_styles": {
                "border_style": "red"
            }
        }
    ]
))
def cli(option1, option2):
    pass

@cli.command
@click.option("--option1", option_group_name="foo")
@click.option("--option2")
@click.option("--option3")
def subcommand(option1, option2, option3):
    pass

cli()

In the above example, a few things are happening of note:

Like I said, I'm not sure what should happen here. Open to ideas!

Lastly, all of this behavior can get quite complex and would benefit a ton from being properly documented, so I wonder if documentation should be considered a hard prerequisite for this feature. 😅