typer-cli icon indicating copy to clipboard operation
typer-cli copied to clipboard

Support extended type definition for more explicit semantics.

Open ZSmallX opened this issue 5 years ago • 0 comments

from typing import Optional

import typer

app = typer.Typer()


@app.command()
def hello(name: str= ''):
    if name:
        typer.echo(f"Hello {name}")
    else:
        typer.echo("Hello World!")

Extending the typing may help understanding the semantics, which make it more explicit. It can establish a strong connection between func arguments and CLI arguments? And make it less "magic".

Like:

@app.command()
def hello(name: cli_str= ''):
    if name:
        typer.echo(f"Hello {name}")
    else:
        typer.echo("Hello World!")

Personal opinion, welcome for discussion~

ZSmallX avatar Dec 19 '20 14:12 ZSmallX