Exemple #1
0
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()
Exemple #2
0
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()
Exemple #3
0
def test_no_subcommands():
    app = Application([arg("--list", "-l", action="store_true")])
    args = app.parse_args(["-l"])
    assert args.list
Exemple #4
0
def app():
    yield Application()
Exemple #5
0
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}")