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

Allow typing "help" instead of ":help" #9

Open
cool-RR opened this issue Jul 30, 2016 · 7 comments
Open

Allow typing "help" instead of ":help" #9

cool-RR opened this issue Jul 30, 2016 · 7 comments

Comments

@cool-RR
Copy link
Contributor

cool-RR commented Jul 30, 2016

How are users supposed to figure out that they should type :help rather than help? Go to the click-repl GitHub page and read about it? I'm preparing a script for people who don't care about my script, don't care about click and definitely don't care about click-repl. I want to make the most obvious thing work for them.

@untitaker
Copy link
Collaborator

:help is guaranteed not to clash with the app's subcommands, and it's probably a matter of preference whether to show the REPL or the Click help text on help. So I'd suggest you implement your own subcommand that does this.

@cool-RR cool-RR closed this as completed Jul 31, 2016
@cool-RR
Copy link
Contributor Author

cool-RR commented Jul 31, 2016

Thanks! Can you please give me a pointer on how to write this help command? I looked at the click source code but didn't find an obvious answer.

@untitaker
Copy link
Collaborator

I mean it'd be just a normal subcommand, also available via the normal CLI. I just realized that might be a problem, so this might be an insufficient solution.

On 31 July 2016 17:00:16 CEST, Ram Rachum notifications@github.com wrote:

Thanks! Can you please give me a pointer on how to write this help
command? I looked at the click source code but didn't find an obvious
answer.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#9 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

@cool-RR cool-RR reopened this Aug 1, 2016
@cool-RR
Copy link
Contributor Author

cool-RR commented Aug 1, 2016

Cool, I reopened this issue. Do you agree it should be an option to click-repl to show the help when the user types help? I'm not too concerned about the rare case where it clashes with an actual command called help. First, if we offer it as an option, then people could just not enable it if they have a command called help. Alternatively, you can make it detect whether there's a command called help and if so, don't use our help.

@untitaker
Copy link
Collaborator

This seems to work:

import click
import click_repl

@click.group()
def cli():
    pass

@cli.command()
def test():
    pass

@cli.command()
@click.pass_context
def repl(ctx):
    @cli.command()
    @click.pass_context
    def help(ctx):
        click.echo(ctx.parent.parent.get_help())
        ctx.exit()

    try:
        click_repl.repl(ctx)
    finally:
        del cli.commands['help']

cli()

Quite a hack. Still unsure though if I want anything like that in click-repl though.

@cool-RR
Copy link
Contributor Author

cool-RR commented Aug 15, 2016

Thanks for the code sample. I believe I won't use that because it looks too hacky to me. Thanks anyway.

@mwgamble
Copy link

I solved this by simply doing the following:

click.echo("Run ':help' for help information, or ':quit' to quit.")
click_repl.repl(click.get_current_context())

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

3 participants