tiangolo / typer

Typer, build great CLIs. Easy to code. Based on Python type hints.

Home Page:https://typer.tiangolo.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prompt adding additional characters to prompt output

rlthompson-godaddy opened this issue · comments

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer


app = typer.Typer(no_args_is_help=True)


@app.command(no_args_is_help=True)
def example(
    user: str = typer.Option("", envvar="EXAMPLE_USER", prompt="user", help="example user to print"),
    password: str = typer.Option("", envvar="EXAMPLE_PASSWORD", prompt="password", hide_input=True, help="example password to print")
    ):
    """Example command."""
    print(f"{user} | {password}")

Description

  • I am creating a simple cli command that has optional parameters that take in a user name and password
  • When running the above command, I notice that the prompt is adding [] to the prompt string:
user []:
password []:
  • I have tried this without a custom prompt string, by setting prompt to true prompt=True but the issue occurs there too
  • What I expect to occur is that [] would not be present in the prompt string output to CLI

Operating System

Linux

Operating System Details

Alma Linux 9

Typer Version

0.6.1

Python Version

Python 3.8.15

Additional Context

The above example code is just that, an example. The actual command also has positional arguments and is itself a nested subcommand. Don't know if that impacts this.

Hey

I've did not verify that one but Ive you really dont want these [] you could add a callback like this to format the value passed from the input.
https://typer.tiangolo.com/tutorial/commands/context/

import typer


app = typer.Typer(no_args_is_help=True)

def some_callback(ctx, parameter, value):
    print(value)


@app.command(no_args_is_help=True)
def example(
    user: str = typer.Option("", envvar="EXAMPLE_USER", prompt="user", help="example user to print", callback=some_callback) ):
    """Example command."""
    print(f"{user} | {password}")

I think that is showing the default value, an empty string.

You could also try to prompt the user manually.

This comes directly from Click, so there's not really much that Typer can do about it. 😅

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.