-
Notifications
You must be signed in to change notification settings - Fork 34
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
Prevent rewrapping with \b
#24
Comments
Yes good point, it would be nice to support all of the click escape markers - |
Ok, looks like the |
Ok, that hopefully got all of the various places that Let me know how you get on with the new code - thanks for the issue! 😀 |
Works perfectly. Thanks for such a quick fix! |
I'm still having this issue, although it's working perfectly with just Click. import rich_click as click
@click.group(context_settings={'help_option_names': ['-h', '--help']})
@click.pass_context
def airflow_cmd(ctx):
pass
@airflow_cmd.group('users')
@click.pass_context
def users(ctx):
"""Commands for managing users"""
@users.command('create')
@click.option('-f', '--firstname', metavar='FIRSTNAME', required=True, type=str, help="First name of the user")
@click.option('-l', '--lastname', metavar='LASTNAME', required=True, type=str, help="Last name of the user")
@click.option('-e', '--email', metavar='EMAIL', required=True, type=str, help="Email of the user")
@click.option('-u', '--username', metavar='USERNAME', required=True, type=str, help="Username of the user")
@click.password_option('-p', '--password', metavar='PASSWORD', help="Password of the user, required to create a user without --use-random-password")
@click.option('--use-random-password', is_flag=True, default=False, help="Do not prompt for password. Use random string instead. Required to create a user without --password")
@click.option('-r', '--role', metavar='ROLE', required=True, help="Role of the user, pre-existing roles include Admin, User, Op, Viewer, and Public")
@click.pass_context
@cli_utils.action_cli(check_db=True)
def users_create(ctx, firstname, lastname, email, username, password, use_random_password, role):
"""
Creates new user in the DB
Example
\b
To create a user with "Admin" role and username "admin":
\b
$ airflow users create \\
--username admin \\
--firstname FIRST_NAME \\
--lastname LAST_NAME \\
--role Admin \\
--email admin@example.org
"""
... Expected output (the double newlines a la #49 being respected would be nice here, but that's not this issue):
Actual output:
If I'm doing something I shouldn't be doing, please let me know. Is there a good workaround? Can I enable markdown for just this one command and leave the rest of the commands I'm converting to Click using rich markup? Besides this issue, I'm loving Click and Rich-Click. Thank you for making my CLI life so easy and ✨pretty✨! ❤️ |
@blag - just to check, what version of rich-click is this with? |
ok I can't easily run your code example as it doesn't stand alone, but if I paste your docstring into the @cli.command(short_help="Optionally use short-help for the group help text")
@click.option("--all", is_flag=True, help="Get everything")
def download(all):
"""
Creates new user in the DB
Example
To create a user with "Admin" role and username "admin":
\b
$ airflow users create \\
--username admin \\
--firstname FIRST_NAME \\
--lastname LAST_NAME \\
--role Admin \\
--email admin@example.org
"""
print("Downloading") ❯ python examples/click/01_simple.py download --help
Debug mode is off
Usage: 01_simple.py download [OPTIONS]
Creates new user in the DB
Example
To create a user with "Admin" role and username "admin":
$ airflow users create \
--username admin \
--firstname FIRST_NAME \
--lastname LAST_NAME \
--role Admin \
--email admin@example.org
╭─ Options ─────────────────────────────────────────────────────────────────╮
│ --all Get everything │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────╯
|
I thought I had already responded to this but I don't see my comment here so I guess not. The issue I had was that I was using rich-click version 1.3.0, and support for this was released in rich-click version 1.3.1. Once I updated to rich-click 1.3.1, everything works perfectly, as expected. Thank you for your help and apologies for not checking that before commenting. This package is seriously awesome! 😄 |
Ok that's a relief 😅 Thanks for letting me know! |
Hi @ewels,
rich-click
is an awesome package and I love that it's a drop-in replacement forclick
. However, I'm running into a small issue with rewrapping.click
uses the\b
flag to prevent rewrapping for a paragraph, which allows you to preserve newlines in a command's help.rich-click
doesn't seem to support that flag and removes newlines.Say you have a command
foo
:Here's the output of
foo --help
using justclick
:With
rich-click
, the newlines are lost.Using Markdown instead might be an alternative, but would require rewriting docstrings and would break compatibility with
click
. Any chance of support being added for\b
inrich-click
?Thanks!
The text was updated successfully, but these errors were encountered: