-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharg_parser.py
More file actions
188 lines (175 loc) · 5 KB
/
arg_parser.py
File metadata and controls
188 lines (175 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
Provides CLI parsing for Git Py Stats.
"""
# TODO: list is not subscriptable before Python 3.9, so we need to work
# around this. However, Python 3.8 EOLs in October 2024. Let's keep
# using older Python 3 ways of doing this, but mark this as a future
# refactor...whenever I decide to upgrade my own version of Python.
from argparse import ArgumentParser, Namespace
from typing import List, Optional
def parse_arguments(argv: Optional[List[str]] = None) -> Namespace:
"""
Parse command-line arguments and return them.
Args:
argv (Optional[List[str]]): List of arguments to parse (default: None).
Returns:
Namespace: Parsed command-line arguments as a Namespace object.
Example:
args = parse_arguments(['--detailed-git-stats'])
print(args.detailed_git_stats) # True
"""
parser = ArgumentParser(
description="Git Py Stats - A Python Implementation of Git Quick Stats.",
allow_abbrev=False, # Force users to be explicit. Makes testing sane.
)
# Generate Options
parser.add_argument(
"-T",
"--detailed-git-stats",
action="store_true",
help="Give a detailed list of git stats",
)
parser.add_argument(
"-R",
"--git-stats-by-branch",
metavar="BRANCH",
type=str,
help="See detailed list of git stats by branch",
)
parser.add_argument(
"-c",
"--changelogs",
action="store_true",
help="See changelogs",
)
parser.add_argument(
"-L",
"--changelogs-by-author",
metavar='"AUTHOR NAME"',
type=str,
help="See changelogs by author",
)
parser.add_argument(
"-S",
"--my-daily-stats",
action="store_true",
help="See your current daily stats",
)
parser.add_argument(
"-V",
"--csv-output-by-branch",
action="store_true",
help="Output daily stats by branch in CSV format",
)
parser.add_argument(
"-j",
"--json-output",
action="store_true",
help="Save git log as a JSON formatted file to a specified area",
)
# List Options
parser.add_argument(
"-b",
"--branch-tree",
action="store_true",
help="Show an ASCII graph of the git repo branch history",
)
parser.add_argument(
"-D",
"--branches-by-date",
action="store_true",
help="Show branches by date",
)
parser.add_argument(
"-C",
"--contributors",
action="store_true",
help="See a list of everyone who contributed to the repo",
)
parser.add_argument(
"-n",
"--new-contributors",
metavar="DATE",
type=str,
help="List everyone who made their first contribution since a specified date",
)
parser.add_argument(
"-a",
"--commits-per-author",
action="store_true",
help="Displays a list of commits per author",
)
parser.add_argument(
"-d",
"--commits-per-day",
action="store_true",
help="Displays a list of commits per day",
)
parser.add_argument(
"-Y",
"--commits-by-year",
action="store_true",
help="Displays a list of commits per year",
)
parser.add_argument(
"-m",
"--commits-by-month",
action="store_true",
help="Displays a list of commits per month",
)
parser.add_argument(
"-w",
"--commits-by-weekday",
action="store_true",
help="Displays a list of commits per weekday",
)
parser.add_argument(
"-W",
"--commits-by-author-by-weekday",
metavar='"AUTHOR NAME"',
type=str,
help="Displays a list of commits per weekday by author",
)
parser.add_argument(
"-o",
"--commits-by-hour",
action="store_true",
help="Displays a list of commits per hour",
)
parser.add_argument(
"-A",
"--commits-by-author-by-hour",
metavar='"AUTHOR NAME"',
type=str,
help="Displays a list of commits per hour by author",
)
parser.add_argument(
"-z",
"--commits-by-timezone",
action="store_true",
help="Displays a list of commits per timezone",
)
parser.add_argument(
"-Z",
"--commits-by-author-by-timezone",
metavar='"AUTHOR NAME"',
type=str,
help="Displays a list of commits per timezone by author",
)
# Calendar Options
parser.add_argument(
"-k",
"--commits-calendar-by-author",
metavar='"AUTHOR NAME"',
type=str,
help="Show a calendar of commits by author",
)
# Suggest Options
parser.add_argument(
"-r",
"--suggest-reviewers",
action="store_true",
help="Show the best people to contact to review code",
)
# Help option inherited from argparse by default, no need to impl them.
return parser.parse_args(argv)