-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
99 lines (85 loc) · 3.14 KB
/
cli.py
File metadata and controls
99 lines (85 loc) · 3.14 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
import argparse
from commands import init, add, commit, log, reset, checkout, branch, tag
def main():
parser = argparse.ArgumentParser(
prog="cvs.py", description="CLI for a version control utility"
)
subparsers = parser.add_subparsers(
dest="command", help="Available commands", required=True
)
# init command
subparsers.add_parser("init", help="Initialize a repository")
# add command
add_parser = subparsers.add_parser("add", help="Add a file to the staging area")
add_parser.add_argument("file", help="Path to the file to add to staging area")
# commit command
commit_parser = subparsers.add_parser(
"commit", help="Commit changes to the repository"
)
commit_parser.add_argument(
"-m", "--message", required=True, help="The commit message"
)
# log command
subparsers.add_parser("log", help="Show the commit history")
# reset command
reset_parser = subparsers.add_parser(
"reset", help="Reset the current HEAD to a specified state"
)
reset_parser.add_argument("commit_hash", help="The hash of the commit to reset to")
# checkout command
checkout_parser = subparsers.add_parser(
"checkout", help="Switch working directory to the given commit"
)
checkout_parser.add_argument(
"commit_hash", help="The hash of the commit to checkout"
)
# branch commands
branch_parser = subparsers.add_parser("branch", help="Branch operations")
branch_parser.add_argument("name", nargs="?", default=None, help="Branch name")
branch_parser.add_argument(
"-d", "--delete", action="store_true", help="Delete the given branch"
)
# tag commands
tag_parser = subparsers.add_parser("tag", help="Tag operations")
tag_parser.add_argument("name", nargs="?", default=None, help="Tag name")
tag_parser.add_argument(
"-d", "--delete", action="store_true", help="Delete the given tag"
)
tag_parser.add_argument(
"-c",
"--commit",
dest="commit_hash",
default=None,
help="Commit hash to tag (defaults to HEAD)",
)
tag_parser.add_argument(
"-m",
"--message",
dest="message",
default=None,
help="Tag message (creates annotated tag)",
)
merge_parser = subparsers.add_parser(
"merge",
help="Merge another branch into the current branch (manual conflict resolution)",
)
merge_parser.add_argument("name", type=str, help="The name of the branch to merge")
args = parser.parse_args()
if args.command == "init":
init.run()
elif args.command == "add":
add.run(args.file)
elif args.command == "commit":
commit.run(args.message)
elif args.command == "log":
log.run()
elif args.command == "reset":
reset.run(args.commit_hash)
elif args.command == "checkout":
checkout.run(args.commit_hash)
elif args.command == "branch":
branch.run(args.name, args.delete)
elif args.command == "tag":
tag.run(args.name, args.delete, args.commit_hash, args.message)
elif args.command == "merge":
branch.merge(args.name)