-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.py
More file actions
46 lines (35 loc) · 1.71 KB
/
Copy pathcli.py
File metadata and controls
46 lines (35 loc) · 1.71 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
import argparse
from enums.output_mode import OutputMode
import helpers.constants as constant
from models.request import Request
from handler_initializer import HandlerInitializer
def setup_request_commandline() -> Request:
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", default=OutputMode.CSV.value,
help="The output mode of the program. This is 'csv' by "
"default, but can be set to 'json' as well.")
parser.add_argument("-i", "--input", help="The input file to be parsed and processed")
parser.add_argument("-t", "--test", default=constant.GENERIC_TEST_NAME, help="The name of the test to be run")
parser.add_argument("-s", "--size", type=int, default=constant.DEFAULT_DATA_SIZE,
help="The size of the random data to be generated; default is 50")
parser.add_argument("-d", "--data",
help="existing data to be used for the test; if provided, it won't generate random data")
try:
args = parser.parse_args()
request = Request(input_file=args.input, output_mode=args.output, test_name=args.test, size=args.size,
data=args.data)
# print(request)
check_request_validity(request)
return request
except Exception as e:
print(f"Error! \n{e}")
quit()
def check_request_validity(request: Request):
if request.data is not None and request.input_file is None:
raise ValueError("Data provided without input file. Please provide input file.")
def main():
request = setup_request_commandline()
processor = HandlerInitializer(request)
processor.process()
if __name__ == '__main__':
main()