from arghelp import Application, arg app = Application() @app.root_command() def main(_): print("Nothing to see here. Move along!") @app.subcommand() def droids(_): print("These aren't the droids you're looking for.") @app.subcommand([arg("number", type=int)]) def square(args): print(args.number**2) app.main()
from arghelp import Application, arg app = Application([arg("--verbose", "-v", action="store_true")]) @app.subcommand([arg("name")]) def hello(args): output = f"Hello, {args.name}!" if args.verbose: output += " How are you today?" print(output) @app.subcommand([arg("name")]) def hi(args): output = f"Hi, {args.name}!" if args.verbose: output += " Hi hi hi!" print(output) app.main()
def test_no_subcommands(): app = Application([arg("--list", "-l", action="store_true")]) args = app.parse_args(["-l"]) assert args.list
def app(): yield Application()
from arghelp import Application, arg app = Application([arg("-v", "--verbose", action="store_true"), arg("name")]) args = app.parse_args() greeting = "hello" if args.verbose else "hi" print(f"{greeting}, {args.name}")