Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (44 loc) · 1.33 KB
/
Copy pathmain.py
File metadata and controls
55 lines (44 loc) · 1.33 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
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Main cli-program, to start it all up by reading command line
options and arguments and then executing whats to be executed.
$ python3 main.py -h
$ python3 main.py hello
$ python3 main.py goodbye
$ python3 main.py --verbose hello world
$ python3 main.py --silent goodbye world
"""
import sys
import cli_parser
verbose_text = """
You have chosen to use the --verbose option.
Your input was: {input}
Unknown arguments: {unknown}
Thank you and good bye!
"""
def main():
"""
Main function where it all starts.
"""
options = cli_parser.parse_options()
command = options["args"]["command"]
silent = options["args"]["silent"]
verbose = options["args"]["verbose"]
if command == "hello":
if silent:
print("Hi!")
elif verbose:
print(verbose_text.format(input=command, unknown=options["unknown_args"]))
else:
print("This is a response to the command: " + command + ":\nHello there!")
if command == "goodbye":
if silent:
print("Bye!")
elif verbose:
print(verbose_text.format(input=command, unknown=options["unknown_args"]))
else:
print("This is a response to the command: " + command + ":\nGoodbye!")
sys.exit()
if __name__ == "__main__":
main()