Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def version_callback(value: bool):
if value:
typer.echo(f"Awesome CLI Version: {__version__}")
raise typer.Exit()
def main(
name: str = typer.Option("World"),
version: bool = typer.Option(None, "--version", callback=version_callback),
):
typer.echo(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)
import typer
def main(username: str):
if username == "root":
typer.echo("The root user is reserved")
raise typer.Abort()
typer.echo(f"New user created: {username}")
if __name__ == "__main__":
typer.run(main)
from pathlib import Path
import typer
APP_NAME = "my-super-cli-app"
def main():
app_dir = typer.get_app_dir(APP_NAME)
config_path: Path = Path(app_dir) / "config.json"
if not config_path.is_file():
typer.echo("Config file doesn't exist yet")
if __name__ == "__main__":
typer.run(main)
import typer
def main():
typer.echo("Hello World")
if __name__ == "__main__":
typer.run(main)
import typer
class NeuralNetwork(str, Enum):
simple = "simple"
conv = "conv"
lstm = "lstm"
def main(network: NeuralNetwork = NeuralNetwork.simple):
typer.echo(f"Training neural network of type: {network.value}")
if __name__ == "__main__":
typer.run(main)
from typing import Tuple
import typer
def main(
names: Tuple[str, str, str] = typer.Argument(
("Harry", "Hermione", "Ron"), help="Select 3 characters to play with"
)
):
for name in names:
typer.echo(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)
def main():
app_dir = typer.get_app_dir(APP_NAME)
app_dir_path = Path(app_dir)
app_dir_path.mkdir(parents=True, exist_ok=True)
config_path: Path = Path(app_dir) / "config.json"
if not config_path.is_file():
config_path.write_text('{"version": "1.0.0"}')
config_file_str = str(config_path)
typer.echo("Opening config directory")
typer.launch(config_file_str, locate=True)
if __name__ == "__main__":
typer.run(main)
if "ipynb_checkpoints" in str(note_book_path):
continue
result = run(cmd + f" {note_book_path}", shell=True)
if result.returncode != 0:
raise RuntimeError(f"failed to run {note_book_path}")
# run auto api-doc
run("sphinx-apidoc ../obsplus -e -M -o api", cwd=doc_path, shell=True)
run("make html", cwd=doc_path, shell=True, check=True)
# ensure html directory was created, return path to it.
expected_path: Path = doc_path / "_build" / "html"
assert expected_path.is_dir(), f"{expected_path} does not exist!"
return str(expected_path)
if __name__ == "__main__":
typer.run(make_docs)