-
Notifications
You must be signed in to change notification settings - Fork 17
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
Can this work with Typer? #49
Comments
I'm going to make a PR with a solution for this, I will report back when I do, however if I forget, you can also look here, I'll post it there too: fastapi/typer#185 |
Actually I just dumped my whole solution in there-- Q for the click-shell devs, would you be interested in integrating the typer-shell solution implemented at that link? Here is the core from typing_extensions import Annotated
from typing import Optional, Callable
from click_shell import make_click_shell
from typer import Context, Typer, Argument
from rich import print
def make_typer_shell(
app: Typer,
prompt: str = ">> ",
intro: str = "\n Welcome to typer-shell! Type help to see commands.\n",
default: Optional[Callable] = None
) -> None:
@app.command(hidden=True)
def help(ctx: Context, command: Annotated[Optional[str], Argument()] = None):
print("\n Type 'command --help' or 'help <command>' for help on a specific command.")
if not command:
ctx.parent.get_help()
return
ctx.parent.command.get_command(ctx, command).get_help(ctx)
@app.command(hidden=True)
def _default(args: Annotated[Optional[str], Argument()] = None):
"""Default command"""
if default:
default(args)
else:
print("Command not found. Type 'help' to see commands.")
@app.callback(invoke_without_command=True)
def launch(ctx: Context):
if ctx.invoked_subcommand is None:
shell = make_click_shell(ctx, prompt=prompt, intro=intro)
shell.default = _default
shell.cmdloop() Happy to make a PR if it is something you are interested in. @clarkperkins |
https://github.com/FergusFettes/typer-shell also added some nice new features to it :) |
I recently started using Typer, which is a layer above Click that parses variable annotations to make arguments and options. Is it possible to use
click-shell
with Typer commands?The text was updated successfully, but these errors were encountered: