-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
72 lines (60 loc) · 1.8 KB
/
cli.py
File metadata and controls
72 lines (60 loc) · 1.8 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
"""
Git Log Analysis CLI
Command line interface
"""
import argparse
import sys
import io
from git_log_analysis.cli import (
setup_generate_parser,
setup_parse_parser,
setup_search_parser,
setup_projects_parser,
)
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")
def main():
"""CLI entry point - provides various features through subcommands"""
parser = argparse.ArgumentParser(
prog="git-log-analysis",
description="A tool for analyzing and searching Git log files",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Subcommands:
generate Extract monthly Git logs from a repository
parse Convert Git log files to JSON
search Search commits from parsed JSON
projects View project list and statistics
For detailed usage of each subcommand:
uv run cli.py generate --help
uv run cli.py parse --help
uv run cli.py search --help
uv run cli.py projects --help
""",
)
# Create subcommand parsers
subparsers = parser.add_subparsers(
title="Available commands",
description="Choose one of the following commands",
dest="command",
help="Command type",
)
# Setup each subcommand
setup_generate_parser(subparsers)
setup_parse_parser(subparsers)
setup_search_parser(subparsers)
setup_projects_parser(subparsers)
# Parse arguments
args = parser.parse_args()
# If no subcommand provided, show help
if not args.command:
parser.print_help()
return 1
# Execute the selected command
if hasattr(args, "func"):
return args.func(args) or 0
else:
parser.print_help()
return 1
if __name__ == "__main__":
sys.exit(main())