|
1
|
|
|
import json |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class CommandLineArgumentsHandling: |
|
5
|
|
|
config_details = [] |
|
6
|
|
|
|
|
7
|
|
|
def fn_build_combined_options(self): |
|
8
|
|
|
str_combined_options = '' |
|
9
|
|
|
for option_index, current_option in enumerate(self.config_details['options']): |
|
10
|
|
|
if current_option is not None: |
|
11
|
|
|
if option_index > 0: |
|
12
|
|
|
str_combined_options += ' ' |
|
13
|
|
|
if self.config_details['options'][current_option]['option_type'] == 'optional': |
|
14
|
|
|
str_combined_options += '[' |
|
15
|
|
|
str_combined_options += '-' + current_option + '|' \ |
|
16
|
|
|
+ self.config_details['options'][current_option]['option_long'] |
|
17
|
|
|
if 'option_sample_value' in self.config_details['options'][current_option]: |
|
18
|
|
|
str_combined_options += ' <' \ |
|
19
|
|
|
+ self.config_details['options'][current_option]['option_sample_value'] \ |
|
20
|
|
|
+ '>' |
|
21
|
|
|
if self.config_details['options'][current_option]['option_type'] == 'optional': |
|
22
|
|
|
str_combined_options += ']' |
|
23
|
|
|
return str_combined_options |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def fn_build_long_options(self): |
|
27
|
|
|
str_long_options = [] |
|
28
|
|
|
for option_index, current_long_option in enumerate(self.config_details['options']): |
|
29
|
|
|
if current_long_option is not None: |
|
30
|
|
|
str_long_options.append(option_index) |
|
31
|
|
|
str_long_options[option_index] = self.config_details['options'][current_long_option]['option_long'] \ |
|
32
|
|
|
+ '=' |
|
33
|
|
|
return str_long_options |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
def fn_build_short_options(self): |
|
37
|
|
|
str_short_options = 'h' |
|
38
|
|
|
for current_short_option in self.config_details['options']: |
|
39
|
|
|
if current_short_option is not None: |
|
40
|
|
|
if self.config_details['options'][current_short_option]['option_type'] == 'mandatory': |
|
41
|
|
|
str_short_options += current_short_option + ':' |
|
42
|
|
|
else: |
|
43
|
|
|
str_short_options += current_short_option |
|
44
|
|
|
return str_short_options |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
def fn_load_configuration(self): |
|
48
|
|
|
with open("config.json", 'r') as json_file: |
|
49
|
|
|
self.config_details = json.load(json_file) |
|
50
|
|
|
|