-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoGit.cs
126 lines (103 loc) · 4.03 KB
/
DemoGit.cs
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
using DemoGit.Services;
namespace DemoGit;
internal class DemoGit(DemoGitCommands demoGitCommands)
{
private readonly DemoGitCommands _demoGitCommands = demoGitCommands;
public async Task HandleDemoGitCommandAsync(string arguments)
{
if(string.IsNullOrWhiteSpace(arguments))
{
throw new ArgumentException("Error: No arguments provided for the 'demogit' command.");
}
var parts = arguments.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
var command = parts[0].ToLower();
var hash = parts.Length > 1 ? parts[1] : "";
switch(command)
{
case "init":
DemoGitCommands.GitInitialization();
break;
case "remove":
DemoGitCommands.GitRemove();
break;
case "cat-file":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit cat-file <type|size|content> <hash>");
}
var subcommandParts = hash.Split(' ', 2);
if(subcommandParts.Length < 2)
{
throw new ArgumentException("Usage: demogit cat-file <type|size|content> <hash>");
}
var subcommand = subcommandParts[0].ToLower();
var objectHash = subcommandParts[1];
DemoGitCommands.GitCatFile(subcommand, objectHash);
break;
case "hash-object":
DemoGitCommands.HandleHashObjectCommand(parts);
break;
case "ls-tree":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit ls-tree <tree-hash>");
}
DemoGitCommands.GitLsTree(hash);
break;
case "write-tree":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit write-tree -w <tree-hash>");
}
DemoGitCommands.GitWriteTree(hash);
break;
case "add":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit add <file-name|.>");
}
DemoGitCommands.AddToIndex(hash);
break;
case "unstage-all":
DemoGitCommands.UnstageAll();
break;
case "status":
DemoGitCommands.DisplayStatus();
break;
case "commit":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit commit <message>");
}
DemoGitCommands.GitCommit(hash);
break;
case "push":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit push <token> <repository-name>");
}
var pushArgs = hash.Split(' ', 2);
if(pushArgs.Length != 2)
{
throw new ArgumentException("Usage: demogit push <token> <repository-name>");
}
await _demoGitCommands.GitPush(pushArgs[0], pushArgs[1]);
break;
case "clone":
if(string.IsNullOrEmpty(hash))
{
throw new ArgumentException("Usage: demogit clone <token> <repository-url>");
}
var cloneArgs = hash.Split(' ', 2);
if(cloneArgs.Length != 2)
{
throw new ArgumentException("Usage: demogit clone <token> <repository-url>");
}
await DemoGitCommands.GitClone(cloneArgs[0], cloneArgs[1], Directory.GetCurrentDirectory());
break;
default:
DemoGitCommands.DisplayDemoGitHelp();
break;
}
}
}