forked from kyclark/tiny_python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoo.py
More file actions
executable file
·47 lines (35 loc) · 1.15 KB
/
foo.py
File metadata and controls
executable file
·47 lines (35 loc) · 1.15 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
#!/usr/bin/env python
"""
usage: foo.py [-h] [-a STR] [-i INT] [-f FILE] [-o] <positional>
Rock the Casbah
positional arguments:
<positional> A positional argument
options:
-h, --help show this help message and exit
-a STR, --arg STR A named string argument [default: ''] [type: str]
-i INT, --int INT A named integer argument [default: 0] [type: int]
-f FILE, --file FILE A readable file [default: None] [type: path]
-o, --on A boolean flag [default: False]
"""
from pathlib import Path
from type_docopt import docopt
from box import Box
def get_args():
"""Get command-line arguments"""
return Box(docopt(__doc__, types={"path": Path}))
def main():
"""Make a jazz noise here"""
args = get_args()
print(args)
str_arg = args.arg
int_arg = args.int
file_arg = args.file
flag_arg = args.on
pos_arg = args.positional_
print(f"str_arg = {str_arg!r}")
print(f"int_arg = {int_arg}")
print(f"file_arg = {file_arg.name if file_arg else ''!r}")
print(f"flag_arg = {flag_arg}")
print(f"positional = {pos_arg!r}")
if __name__ == "__main__":
main()