click-repl icon indicating copy to clipboard operation
click-repl copied to clipboard

[feature request] start with repl mode without an extra command

Open derVedro opened this issue 1 year ago • 3 comments

May be it's already possible but I could not figure out how to bring the app direct into REPL mode just by starting it without an additional command. Also I would prefer if calling $ myapp would not show me the help handler but do the same as $ myapp repl. If both ways could start interactive mode it would be great.

derVedro avatar Jun 02 '24 21:06 derVedro

You can already do it by calling the click_repl.repl() function inside the main group which holds all of your other commands, like this

from click_repl import repl
import click

@click.group(invoke_without_command=True)
@click.pass_context
def main(ctx: click.Context):
    if ctx.invoked_subcommand:
        repl(ctx)
    ...

# Rest of your code/commands

GhostOps77 avatar Jun 14 '24 11:06 GhostOps77

Thank you! It works like a charm, I just adjusted it to:

if not ctx.invoked_subcommand:
    repl(ctx)

derVedro avatar Jun 15 '24 19:06 derVedro

This isn't really a satisfactory answer. I don't want the repl to be the entry point of my application, because I want the cli and the repl to be entirely different contexts, with entirely different subcommands and options.

ali1234 avatar Sep 10 '24 11:09 ali1234