1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
|
3
|
1 |
|
"""Plugin for Git.""" |
4
|
|
|
|
5
|
1 |
|
import argparse |
6
|
1 |
|
|
7
|
|
|
from . import __version__, common |
8
|
1 |
|
from .cli import _get_command, _run_command |
9
|
1 |
|
|
10
|
1 |
|
|
11
|
|
|
PROG = 'git deps' |
12
|
1 |
|
DESCRIPTION = "Use GitMan (v{}) to install repositories.".format(__version__) |
13
|
1 |
|
|
14
|
|
|
|
15
|
1 |
|
def main(args=None): |
16
|
|
|
"""Process command-line arguments and run the Git plugin.""" |
17
|
|
|
|
18
|
1 |
|
# Main parser |
19
|
|
|
parser = argparse.ArgumentParser(prog=PROG, description=DESCRIPTION) |
20
|
|
|
parser.add_argument( |
21
|
|
|
'-F', |
22
|
1 |
|
'--force', |
23
|
1 |
|
action='store_true', |
24
|
|
|
help="overwrite uncommitted changes in dependencies", |
25
|
|
|
) |
26
|
|
|
parser.add_argument( |
27
|
1 |
|
'-f', |
28
|
|
|
'--force-interactive', |
29
|
|
|
action='store_true', |
30
|
|
|
dest='force_interactive', |
31
|
|
|
help="interactively overwrite uncommitted changes in dependencies", |
32
|
|
|
) |
33
|
1 |
|
parser.add_argument( |
34
|
1 |
|
'-s', |
35
|
|
|
'--skip-changes', |
36
|
|
|
action='store_true', |
37
|
1 |
|
dest='skip_changes', |
38
|
|
|
help="skip dependencies with uncommitted changes", |
39
|
|
|
) |
40
|
|
|
parser.add_argument( |
41
|
1 |
|
'-c', |
42
|
|
|
'--clean', |
43
|
1 |
|
action='store_true', |
44
|
|
|
help="delete ignored files when updating dependencies", |
45
|
|
|
) |
46
|
|
|
|
47
|
|
|
# Options group |
48
|
1 |
|
group = parser.add_mutually_exclusive_group() |
49
|
|
|
|
50
|
|
|
# Update option |
51
|
|
|
group.add_argument( |
52
|
|
|
'-u', |
53
|
|
|
'--update', |
54
|
1 |
|
const='update', |
55
|
|
|
help="update dependencies to the latest versions", |
56
|
|
|
action='store_const', |
57
|
|
|
dest='command', |
58
|
|
|
) |
59
|
|
|
parser.add_argument( |
60
|
1 |
|
'-a', |
61
|
|
|
'--all', |
62
|
|
|
action='store_true', |
63
|
1 |
|
dest='recurse', |
64
|
1 |
|
help="include nested dependencies when updating", |
65
|
1 |
|
) |
66
|
1 |
|
parser.add_argument( |
67
|
1 |
|
'-L', |
68
|
1 |
|
'--skip-lock', |
69
|
1 |
|
action='store_false', |
70
|
|
|
dest='lock', |
71
|
|
|
default=True, |
72
|
1 |
|
help="disable recording of updated versions", |
73
|
|
|
) |
74
|
|
|
|
75
|
1 |
|
# Display option |
76
|
1 |
|
group.add_argument( |
77
|
|
|
'-l', |
78
|
|
|
'--list', |
79
|
|
|
const='list', |
80
|
|
|
help="display the current version of each dependency", |
81
|
|
|
action='store_const', |
82
|
|
|
dest='command', |
83
|
|
|
) |
84
|
|
|
|
85
|
|
|
# Uninstall option |
86
|
|
|
group.add_argument( |
87
|
|
|
'-x', |
88
|
|
|
'--uninstall', |
89
|
|
|
const='uninstall', |
90
|
|
|
help="delete all installed dependencies", |
91
|
|
|
action='store_const', |
92
|
|
|
dest='command', |
93
|
|
|
) |
94
|
|
|
parser.add_argument( |
95
|
|
|
'-k', |
96
|
|
|
'--keep-location', |
97
|
|
|
action='store_true', |
98
|
|
|
dest='keep_location', |
99
|
|
|
default=False, |
100
|
|
|
help='keep top level folder location', |
101
|
|
|
) |
102
|
|
|
|
103
|
|
|
# Parse arguments |
104
|
|
|
namespace = parser.parse_args(args=args) |
105
|
|
|
|
106
|
|
|
# Modify arguments to match CLI interface |
107
|
|
|
if not namespace.command: |
108
|
|
|
namespace.command = 'install' |
109
|
|
|
namespace.name = [] |
110
|
|
|
namespace.root = None |
111
|
|
|
namespace.depth = None |
112
|
|
|
namespace.allow_dirty = True |
113
|
|
|
namespace.fetch = True |
114
|
|
|
|
115
|
|
|
# Configure logging |
116
|
|
|
common.configure_logging() |
117
|
|
|
|
118
|
|
|
# Run the program |
119
|
|
|
function, args, kwargs = _get_command(None, namespace) |
120
|
|
|
_run_command(function, args, kwargs) |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
if __name__ == '__main__': # pragma: no cover (manual test) |
124
|
|
|
main() |
125
|
|
|
|