Completed
Pull Request — develop (#109)
by Jace
02:18
created

gitman.main()   A

Complexity

Conditions 2

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 2
Metric Value
cc 2
dl 0
loc 59
ccs 22
cts 22
cp 1
crap 2
rs 9.597

How to fix   Long Method   

Long Method

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:

1
#!/usr/bin/env python3
2
3 1
"""Plugin for Git."""
4
5 1
import argparse
6 1
import logging
7
8 1
from . import PLUGIN, NAME, __version__
9 1
from . import common
10 1
from .cli import _get_command, _run_command
11
12 1
PROG = 'git ' + PLUGIN
13 1
DESCRIPTION = "Use {} (v{}) to install repostories.".format(NAME, __version__)
14
15 1
log = logging.getLogger(__name__)
16
17
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(
0 ignored issues
show
Coding Style introduced by
Usage of * or ** arguments should usually be done with care.

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.

Loading history...
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(
0 ignored issues
show
Coding Style introduced by
Usage of * or ** arguments should usually be done with care.

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.

Loading history...
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(
0 ignored issues
show
Coding Style introduced by
Usage of * or ** arguments should usually be done with care.

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.

Loading history...
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
78
79
if __name__ == '__main__':  # pragma: no cover (manual test)
80
    main()
81