Test Failed
Push — master ( 76e2e7...3e515d )
by Daniel
01:32
created

CommandLineArgumentsHandling.fn_build_combined_options()   A

Complexity

Conditions 5

Size

Total Lines 16
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nop 1
dl 0
loc 16
rs 9.1832
c 0
b 0
f 0
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
                str_option_crt = '-' + current_option + '|' \
12
                                 + self.config_details['options'][current_option]['option_long']
13
                if 'option_sample_value' in self.config_details['options'][current_option]:
14
                    str_option_crt += ' <' \
15
                                       + self.config_details['options'][current_option]['option_sample_value'] + '>'
16
                if self.config_details['options'][current_option]['option_type'] == 'optional':
17
                    str_combined_options += ' [' + str_option_crt + '|if omitted default value will be considered: ' \
18
                                            + str(self.config_details['options'][current_option]['default_value']) \
19
                                            + ']'
20
                else:
21
                    str_combined_options += ' ' + str_option_crt
22
        return str_combined_options
23
24
25
    def fn_build_long_options(self):
26
        str_long_options = []
27
        for option_index, current_long_option in enumerate(self.config_details['options']):
28
            if current_long_option is not None:
29
                str_long_options.append(option_index)
30
                str_long_options[option_index] = self.config_details['options'][current_long_option]['option_long'] \
31
                                                 + '='
32
        return str_long_options
33
34
35
    def fn_build_short_options(self):
36
        str_short_options = 'h'
37
        for current_short_option in self.config_details['options']:
38
            if current_short_option is not None:
39
                if self.config_details['options'][current_short_option]['option_type'] == 'mandatory':
40
                    str_short_options += current_short_option + ':'
41
                else:
42
                    str_short_options += current_short_option
43
        return str_short_options
44
45
46
    def fn_load_configuration(self):
47
        with open("config.json", 'r') as json_file:
48
            self.config_details = json.load(json_file)
49