Skip to content

Instantly share code, notes, and snippets.

@podhmo
Last active Apr 17, 2021
Embed
What would you like to do?
def hello(*, name: str) -> None:
print(f"hello {name}")
def main() -> None:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--name", required=True)
args = parser.parse_args()
params = vars(args).copy()
hello(**params)
if __name__ == "__main__":
main()
def hello(*, name: str) -> None:
print(f"hello {name}")
def main() -> None:
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--name", required=True)
args = parser.parse_args()
params = vars(args).copy()
fn = hello
if bool(os.getenv("FAKE_CALL")):
from inspect import getcallargs
from functools import partial
fn = partial(getcallargs, fn)
fn(**params)
if __name__ == "__main__":
main()

hello

Usage:

$ hello [OPTIONS]

Options:

  • --name TEXT: name of greeting [default: ]
  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.
import typer
def hello(*, name: str = typer.Option("", help="name of greeting")) -> None:
print(f"hello {name}")
if __name__ == "__main__":
typer.run(hello)
from handofcats import as_command
@as_command
def hello(*, name: str) -> None:
print(f"hello {name}")
def hello(*, name: str) -> None:
print(f"hello {name}")
def main(argv=None):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--name', required=True, help='-')
args = parser.parse_args(argv)
params = vars(args).copy()
action = hello
return action(**params)
if __name__ == '__main__':
main()
00:
python $(shell echo $@*.py) --name world
01:
FAKE_CALL=1 python $(shell echo $@*.py) --name world
02:
python $(shell echo $@*.py) --name world
typer $(shell echo $@*.py) utils docs > $@hello-doc.md
03:
python $(shell echo $@*.py) --name world
python $(shell echo $@*.py) --simple --expose > exposed.py
# python $(shell echo $@*.py) --expose > exposed.py
typer
typer-cli
handofcats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment