Conditions | 5 |
Total Lines | 53 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python3 |
||
38 | def cli_args(): |
||
39 | parser = argparse.ArgumentParser( |
||
40 | description='inji - render jinja templates' |
||
41 | ) |
||
42 | required = parser.add_argument_group('required arguments') |
||
43 | |||
44 | required.add_argument('-t', '-f', '--template', |
||
45 | action = 'store', required=False, type=utils.file_or_stdin, |
||
46 | dest='template', default='-', |
||
47 | help='/path/to/template.j2 (defaults to -)' |
||
48 | ) |
||
49 | |||
50 | parser.add_argument('-j', '--json-config', '-c', |
||
51 | action = 'store', required=False, |
||
52 | type=lambda x: utils.json_parse(x), |
||
53 | dest='json_string', |
||
54 | help="-c '{ \"foo\": \"bar\", \"fred\": \"wilma\" }'" |
||
55 | ) |
||
56 | |||
57 | parser.add_argument('-k', '--kv-config', '-d', |
||
58 | action = 'store', required=False, |
||
59 | type=lambda x: utils.kv_parse(x), |
||
60 | dest='kv_pair', |
||
61 | help='-d foo=bar -d fred=wilma' |
||
62 | ) |
||
63 | |||
64 | parser.add_argument('-o', '--overlay-dir', |
||
65 | action = 'append', required=False, type=lambda p, t='dir': utils.path(p, t), |
||
66 | dest='overlay_dir', default=[], |
||
67 | help='/path/to/overlay/' |
||
68 | ) |
||
69 | |||
70 | parser.add_argument('-v', '-p', '--vars-file', '--vars', |
||
71 | action = 'append', required=False, type=lambda p, t='file': utils.path(p, t), |
||
72 | dest='vars_file', default=[], |
||
73 | help='/path/to/vars.yaml' |
||
74 | ) |
||
75 | |||
76 | parser.add_argument('--strict-mode', '-s', |
||
77 | action = 'store', required=False, type=str, |
||
78 | dest='undefined_variables_mode', default='strict', |
||
79 | choices=[ 'strict', 'empty', 'keep', |
||
80 | 'StrictUndefined', 'Undefined', 'DebugUndefined' ], |
||
81 | help='Refer to http://jinja.pocoo.org/docs/2.10/api/#undefined-types' |
||
82 | ) |
||
83 | |||
84 | required.add_argument('--version', |
||
85 | action = 'version', |
||
86 | version=_version(), |
||
87 | help='print version number ({})'.format(_version()) |
||
88 | ) |
||
89 | |||
90 | return parser.parse_args() |
||
91 | |||
164 |