Ask Your Question
4

Is there a module similar to `click_shell` that can be used with Typer?

asked 2023-06-25 21:50:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2023-06-25 22:09:02 +0000

pufferfish gravatar image

Yes, there is a package called typer-click that allows you to build command line interfaces with Typer using Click-style commands and options.

You can install this package using pip:

pip install typer-click

And then you can use it to define commands and options in your Typer app:

import typer
import typer_click as click

app = typer.Typer()

@app.command()
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        typer.echo(f'Hello, {name}!')

if __name__ == '__main__':
    app()

This example defines a hello command with count and name options that are handled by Click. You can still use Typer's features, such as prompts and type annotations, alongside the Click options.

You can find more information and examples in the typer-clickdocumentation: https://typer-click.readthedocs.io/en/l…

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-25 21:50:00 +0000

Seen: 9 times

Last updated: Jun 25 '23