-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
128 lines (125 loc) · 4.03 KB
/
Copy pathMain.java
File metadata and controls
128 lines (125 loc) · 4.03 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
package gitlet;
import java.io.File;
/** Driver class for Gitlet, the tiny stupid version-control system.
* @author Dylan Goetting
*/
public class Main {
/** Usage: java gitlet.Main ARGS, where ARGS contains
* <COMMAND> <OPERAND> .... */
public static void main(String... args) {
if (args.length == 0) {
System.out.println("Please enter a command.");
} else if (args[0].equals("init")) {
if (args.length > 1) {
System.out.println("Incorrect operands.");
} else {
new Repo();
}
} else {
File repoPath = new File(".gitlet/dummyRepo");
try {
Repo r = Utils.readObject(repoPath, Repo.class);
switch (args[0]) {
case "add":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.add(args[1]);
}
break;
case "commit":
if (args.length > 2) {
System.out.println("Incorrect operands.");
} else if (args.length == 1) {
System.out.println("Please enter a commit message");
} else {
r.commit(args[1]);
}
break;
case "rm":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.rm(args[1]);
}
break;
case "log":
if (args.length > 1) {
System.out.println("Incorrect operands.");
} else {
r.log();
}
break;
case "global-log":
if (args.length > 1) {
System.out.println("Incorrect operands.");
} else {
r.glog();
}
break;
default:
helper(args, r);
}
} catch (IllegalArgumentException i) {
System.out.println("Not in an initialized Gitlet directory.");
}
}
}
/** helper ARGS R. **/
public static void helper(String[] args, Repo r) {
switch (args[0]) {
case "find":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.find(args[1]);
}
break;
case "status":
if (args.length > 1) {
System.out.println("Incorrect operands.");
} else {
r.status();
}
break;
case "checkout":
if (args.length < 2 || args.length > 4) {
System.out.println("Incorrect operands.");
} else {
r.checkout(args);
}
break;
case "branch":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.branch(args[1]);
}
break;
case "rm-branch":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.rmbranch(args[1]);
}
break;
case "reset":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.reset(args[1]);
}
break;
case "merge":
if (args.length != 2) {
System.out.println("Incorrect operands.");
} else {
r.merge(args[1]);
}
break;
default:
System.out.println("No command with that name exists.");
break;
}
}
}