Passed
Push — master ( 7b7a8f...b7c92c )
by Daniel
04:03
created

tableau_hyper_management.CommandLineArgumentsManagement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CommandLineArgumentsManagement.parse_arguments() 0 16 3
A CommandLineArgumentsManagement.translate_default_to_action() 0 8 3
1
"""
2
CommandLineArgumentManagement - library to manage input parameters from command line
3
4
This library allows handling pre-configured arguments to be received from command line and use them
5
to call the main package functions
6
"""
7
8
import argparse
9
10
11
class CommandLineArgumentsManagement:
12
13
    def parse_arguments(self, configuration_details):
14
        parser = argparse.ArgumentParser()
15
        for input_key, attributes in configuration_details.items():
16
            action_value = self.translate_default_to_action(attributes['default_value'])
17
            if action_value is None:
18
                parser.add_argument('-' + input_key, '--' + attributes['option_long'],
19
                                    required=attributes['option_required'],
20
                                    default=attributes['default_value'],
21
                                    help=attributes['option_sample_value'])
22
            else:
23
                parser.add_argument('-' + input_key, '--' + attributes['option_long'],
24
                                    required=attributes['option_required'],
25
                                    default=attributes['default_value'],
26
                                    action=action_value)
27
        parser.add_argument('-v', '--verbose', required=False, default=False, action='store_true')
28
        return parser.parse_args()
29
30
    @staticmethod
31
    def translate_default_to_action(given_default_value):
32
        if given_default_value == True:
33
            return 'store_true'
34
        elif given_default_value == False:
35
            return 'store_false'
36
        else:
37
            return None
38