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

Would it be possible to apply the Rich formatting without monkey patching #8

Closed
ewels opened this issue Feb 13, 2022 · 1 comment
Closed

Comments

@ewels
Copy link
Owner

ewels commented Feb 13, 2022

Would it be possible to apply the Rich formatting without monkey patching?

I was thinking that the rich_click namespace could replicate the click namespace. But supply customized version of Click objects (via inheritance).

This is what we have currently:

import click
import rich_click

class RichClickGroup(click.Group):
    def format_help(self, ctx, formatter):
        rich_click.rich_format_help(self, ctx, formatter)
class RichClickCommand(click.Command):
    def format_help(self, ctx, formatter):
        rich_click.rich_format_help(self, ctx, formatter)

@click.group(cls=RichClickGroup)
@click.option('--debug/--no-debug', default=False)
def cli(debug):
    click.echo(f"Debug mode is {'on' if debug else 'off'}")

@cli.command(cls=RichClickCommand)
def sync():
    click.echo('Syncing')

But I think it could be as simple (for the user at least) as this:

import rich_click as click 

@click.group()
@click.option('--debug/--no-debug', default=False)
def cli(debug):
    click.echo(f"Debug mode is {'on' if debug else 'off'}")

@cli.command()
def sync():
    click.echo('Syncing')

Thoughts?

Originally posted by @willmcgugan in #7

@ewels ewels mentioned this issue Feb 13, 2022
@ewels
Copy link
Owner Author

ewels commented Feb 17, 2022

Done in #10

@ewels ewels closed this as completed Feb 17, 2022
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

No branches or pull requests

1 participant