Conditions | 2 |
Total Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 2 |
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 |
||
18 | 1 | def main(args=None): |
|
19 | """Process command-line arguments and run the Git plugin.""" |
||
20 | |||
21 | # Main parser |
||
22 | 1 | parser = argparse.ArgumentParser(prog=PROG, description=DESCRIPTION) |
|
23 | 1 | parser.add_argument( |
|
24 | '-f', '--force', action='store_true', |
||
25 | help="overwrite uncommitted changes in dependencies", |
||
26 | ) |
||
27 | 1 | parser.add_argument( |
|
28 | '-c', '--clean', action='store_true', |
||
29 | help="keep ignored files when updating dependencies", |
||
30 | ) |
||
31 | |||
32 | # Options group |
||
33 | 1 | group = parser.add_mutually_exclusive_group() |
|
34 | 1 | shared = dict(action='store_const', dest='command') |
|
35 | |||
36 | # Update option |
||
37 | 1 | group.add_argument( |
|
|
|||
38 | '-u', '--update', const='update', |
||
39 | help="update dependencies to the latest versions", **shared |
||
40 | ) |
||
41 | 1 | parser.add_argument('-a', '--all', action='store_true', dest='recurse', |
|
42 | help="include nested dependencies when updating") |
||
43 | 1 | parser.add_argument('-L', '--no-lock', |
|
44 | action='store_false', dest='lock', default=True, |
||
45 | help="skip recording of versions for later reinstall") |
||
46 | |||
47 | # Display option |
||
48 | 1 | group.add_argument( |
|
49 | '-l', '--list', const='list', |
||
50 | help="display the current version of each dependency", **shared |
||
51 | ) |
||
52 | |||
53 | # Uninstall option |
||
54 | 1 | group.add_argument( |
|
55 | '-x', '--uninstall', const='uninstall', |
||
56 | help="delete all installed dependencies", **shared |
||
57 | ) |
||
58 | |||
59 | # Parse arguments |
||
60 | 1 | namespace = parser.parse_args(args=args) |
|
61 | |||
62 | # Modify arguments to match CLI interface |
||
63 | 1 | if not namespace.command: |
|
64 | 1 | namespace.command = 'install' |
|
65 | 1 | namespace.name = [] |
|
66 | 1 | namespace.root = None |
|
67 | 1 | namespace.depth = None |
|
68 | 1 | namespace.allow_dirty = True |
|
69 | 1 | namespace.fetch = True |
|
70 | |||
71 | # Configure logging |
||
72 | 1 | common.configure_logging() |
|
73 | |||
74 | # Run the program |
||
75 | 1 | function, args, kwargs, exit_msg = _get_command(None, namespace) |
|
76 | 1 | _run_command(function, args, kwargs, exit_msg) |
|
77 | |||
81 |
Generally, there is nothing wrong with usage of
*
or**
arguments. For readability of the code base, we suggest to not over-use these language constructs though.For more information, we can recommend this blog post from Ned Batchelder including its comments which also touches this aspect.