-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLI.py
93 lines (68 loc) · 2.46 KB
/
CLI.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import argparse
from Converter import Generator, ReadYAML, run
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
parser = argparse.ArgumentParser(description='WIP CLI for compose>template',)
li_ = []
services = ReadYAML().services
service = ""
msg = """Please choose from this list:"""
for i in services:
it = i + 1
msg += "\n" + str(it) + ": " + str(services[i])
li_.append(it)
parser.add_argument('-s', '--service', choices=li_, type=int,
help='list servers, storage, or both (default: %(default)s)')
parser.add_argument('-a', '--automated', action='store_true', help="Generates files from best-guess")
parser.add_argument('-m', '--manual', action='store_true', help="To escape entrypoint imn docker")
parser.add_argument('-t', '--templateurl', help="Sets Template URL")
parser.add_argument('-n', '--name', help="Sets Name")
parser.add_argument('-g', '--repository', help="Sets Repository")
parser.add_argument('-r', '--registry', help="Sets Registry")
parser.add_argument('-u', '--project', help="Sets Project")
parser.add_argument('-i', '--icon', help="Sets Icon URL")
parser.add_argument('-b', '--bindtime', help="Sets Bindtime", type=str2bool)
parser.add_argument('-p', '--privileged', help="Sets Privileged")
parser.add_argument('-o', '--overview', help="Sets Overview")
parser.add_argument('-d', '--description', help="Sets Description")
args = parser.parse_args()
meta_kwargs = {}
if args.description:
meta_kwargs["description"] = args.description
if args.name:
meta_kwargs["name"] = args.name
if args.repository:
meta_kwargs["repository"] = args.repository
if args.registry:
meta_kwargs["registry"] = args.registry
if args.project:
meta_kwargs["project"] = args.project
if args.icon:
meta_kwargs["icon"] = args.icon
if args.bindtime:
meta_kwargs["bindtime"] = args.bindtime
if args.privileged:
meta_kwargs["privileged"] = args.privileged
if args.overview:
meta_kwargs["overview"] = args.overview
if args.automated:
run()
elif args.manual:
print(msg)
elif not args.service:
print(msg)
if args.service:
service = services[args.service - 1]
elm = Generator(service)
elm.metadata(**meta_kwargs)
elm.variable()
elm.network()
elm.data()
elm.write()