Skip to content
Discussion options

You must be logged in to vote

Oh, sorry.. You are right.

Is it suitable for you to use SecretStr from Pydantic?

from pydantic import SecretStr
from typer import Option, Typer, echo

cli = Typer(no_args_is_help=True, add_completion=False)

@cli.command()
def deploy(
    api_token: SecretStr = Option(..., parser=SecretStr)
) -> None:
    echo(api_token.get_secret_value())
    raise Exception(f"{api_token=}")

if __name__ == "__main__":
    cli()

As I understand, the way you would do it with Click is to set expose_value=False and use callback to store it into context:

from typer import Option, Typer, echo, Context

cli = Typer(no_args_is_help=True, add_completion=False)


def store_to_context(ctx: Context, param, value):…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@HansAarneLiblik
Comment options

@YuriiMotov
Comment options

Answer selected by HansAarneLiblik
@HansAarneLiblik
Comment options

@lachaib
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants