-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsonar.py
executable file
·61 lines (42 loc) · 1.64 KB
/
sonar.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
#!/usr/bin/env python3
import argparse
from typing import Dict, List
import sys
from sonar.sonar import process_image
def convert_parser_arguments_to_key_value(parameters: List[str]) -> Dict[str, str]:
"""Converts a list of parameters passed to `ArgumentParser` into a dictionary.
`parser.parse_args` will convert a series of arguments like:
`sonar.py -p key1=value1 -p key2=value2`
Into a list with each one of the entries as strings:
`["key1=value1", "key2=value2"]`
This function will convert this List into a Dict of (key, value).
>>> convert_parser_arguments_to_key_value(["a=1", "b=2"])
{"a": "1", "b": "2"}
"""
if parameters is None:
return {}
d = {}
for p in parameters:
entry = p[0].split("=")
d[entry[0]] = entry[1]
return d
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--image", required=True)
parser.add_argument("-p", dest="parameters", nargs=1, action="append")
parser.add_argument("--pipeline", default=False, action="store_true")
parser.add_argument("--skip-tags", default="", type=str)
parser.add_argument("--include-tags", default="", type=str)
parser.add_argument("--inventory", default="inventory.yaml", type=str)
args = parser.parse_args()
build_args = convert_parser_arguments_to_key_value(args.parameters)
process_image(
image_name=args.image,
skip_tags=args.skip_tags,
include_tags=args.include_tags,
build_args=build_args,
inventory=args.inventory,
build_options={"pipeline": args.pipeline},
)
if __name__ == "__main__":
sys.exit(main())