-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcli.js
More file actions
93 lines (90 loc) · 2.3 KB
/
cli.js
File metadata and controls
93 lines (90 loc) · 2.3 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
#!/usr/bin/env node
const { exec } = require("child_process");
const helptxt = require("./utils/help");
const cmdExec = (cmd) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(stdout);
return;
});
};
const cmdsExec = (cmds) => {
let execNext = () => {
exec(cmds.shift(), (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(stderr);
// return;
} else {
console.log(stdout);
if (cmds.length) execNext();
}
});
};
execNext();
};
switch (process.argv[2]) {
case "i":
cmdExec("git init");
break;
case "s":
cmdExec("git status");
break;
case "st":
cmdExec("git stash");
break;
case "l":
cmdExec("git log");
break;
case "a":
cmdExec(`git add "${process.argv.slice(3).join(" ")}"`);
break;
case "c":
cmdExec(`git commit -m "${process.argv.slice(3).join(" ")}"`);
break;
case "p":
process.argv[4] != null
? cmdsExec([
"git config --global core.safecrlf false",
"git add .",
`git commit -m "${process.argv.slice(3, 4).join(" ")}"`,
`git push origin ${process.argv.slice(4).join(" ")}`,
])
: cmdExec(`git push origin ${process.argv.slice(3).join(" ")}"`);
break;
case "r":
cmdExec(`git remote add origin "${process.argv.slice(3).join(" ")}"`);
break;
case "cb":
cmdExec(`git checkout -b "${process.argv.slice(3).join(" ")}"`);
break;
case "b":
cmdExec(`git checkout "${process.argv.slice(3).join(" ")}"`);
break;
case "bl":
cmdExec(`git blame "${process.argv.slice(3).join(" ")}"`);
break;
case "pl":
cmdExec(`git pull origin "${process.argv.slice(3).join(" ")}"`);
break;
case "help":
console.log("\x1b[42m%s\x1b[0m", "giq help");
console.log("\x1b[4m%s\x1b[0m", helptxt.giqpush);
console.log("\nThis command is equivalent to following git commands\n");
console.log("\x1b[4m%s\x1b[0m", helptxt.gitpush);
console.log("\nAvailable other commands");
console.log("\x1b[36m%s\x1b[0m", helptxt.table);
break;
default:
break;
}