-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (60 loc) · 2.25 KB
/
app.js
File metadata and controls
71 lines (60 loc) · 2.25 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
const Repository = require("./repository");
const { logHeader, logError, logInfo, logSuccess } = require("./utils/logger");
const argv = process.argv.slice(2);
const [command, subcommand, ...args] = argv;
const repo = new Repository();
const banner = `
\x1b[33m██████╗ ██╗ ██╗ ██████╗ ██████╗
██╔══██╗██║ ██║██╔═══██╗██╔═══██╗
██████╔╝██║ ██║██║ ██║██║ ██║
██╔═══╝ ██║ ██║██║ ██║██║ ██║
██║ ╚██████╔╝╚██████╔╝╚██████╔╝
╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ \x1b[0m
`;
if (subcommand === "init") {
console.log(banner);
console.log("\x1b[36mWelcome to BYOG - Build Your Own Git!\x1b[0m\n");
}
if (command === "byog") {
switch (subcommand) {
case "help":
logHeader("BYOG Available Commands");
console.log(`
\x1b[32mbyog init\x1b[0m → Initialize a new repository
\x1b[32mbyog add <file>\x1b[0m → Stage files for commit
\x1b[32mbyog commit -m "msg"\x1b[0m → Commit staged changes
\x1b[32mbyog gc\x1b[0m → Garbage collect loose objects
`);
break;
case "init":
if (repo.init()) logSuccess("Repository initialized successfully!");
process.exit(0)
case "add":
if (args.length === 0) {
logError("Please specify files to add. Example: byog add <file>");
} else {
repo.addPath(...args)
}
break;
case "commit":
if (args[0] === "-m" && args[1]) {
if(repo.commit(args.slice(1).join(" "))){
logSuccess("Commit complete! All staged changes have been saved.");
console.log(
"\n\x1b[36m🔹 Exiting BYOG... See you next time! 🔹\x1b[0m\n"
);
process.exit(0);
}
} else {
logError('Usage: byog commit -m "your message"');
}
break;
case "gc":
repo.gc();
break;
default:
logError("Unknown command. Try `byog help`.");
}
} else {
logError("Unknown command. Did you mean `byog`?");
}