-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharg.py
More file actions
55 lines (43 loc) · 1.22 KB
/
arg.py
File metadata and controls
55 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
#! -*- coding: utf-8 -*-
import click #pip3 install click
'''
@click.command()
@click.option("--username", type=str, help="arg for username", required=True)
@click.option("--passwd", type=str, help="arg for passwd")
def main(username, passwd):
"""
python3 arg.py --help
python3 arg.py --username lsq
python3 arg.py --username=lsq --passwd=0123
"""
print(f"{username}: {passwd}")
if __name__ == "__main__":
main()
'''
@click.command()
@click.option("--old", type=click.Choice(['True', 'False']), help="is old main")
@click.option("--pos", nargs=2, type=int)
@click.option('--digit', type=click.IntRange(0, 10))
@click.argument("name")
def test(old, name, pos):
'''--pos 1 2'''
'''--pos=1 2'''
print(f"{name} is {old}")
print(f"{pos}")
@click.command()
@click.option("--username", type=str, help="arg for username", required=True)
@click.option("--passwd", type=str, help="arg for passwd", default="123")
def login(username, passwd):
print(f"{username}: {passwd}")
@click.group()
def main():
pass
main.add_command(login)
main.add_command(test)
if __name__ == "__main__":
'''
python3 arg.py --help
python3 arg.py login --help
'''
main()