| Total Complexity | 6 |
| Total Lines | 37 |
| Duplicated Lines | 70.27 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 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 | View Code Duplication | 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(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 | return parser.parse_args() |
||
| 28 | |||
| 29 | @staticmethod |
||
| 30 | def translate_default(given_default_value): |
||
| 31 | if given_default_value == True: |
||
| 32 | return 'store_true' |
||
| 33 | elif given_default_value == False: |
||
| 34 | return 'store_false' |
||
| 35 | else: |
||
| 36 | return None |
||
| 37 |