-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (40 loc) · 1.28 KB
/
index.js
File metadata and controls
52 lines (40 loc) · 1.28 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
#!/usr/bin/env node
const { processCommand } = require("./process.js");
const { execute } = require("./execute.js");
const { question } = require("readline-sync");
async function main() {
const command = process.argv[process.argv.length - 1];
let suggestion;
if (command.toLowerCase().includes("git-do") || command.toLowerCase().includes("index.js")) {
console.error("Please enter an input.");
process.exit(1);
}
try {
suggestion = await processCommand(command);
} catch (e) {
console.error("Error executing:");
console.error(` ${e}`);
process.exit(1);
}
if (suggestion.commands.length == 0) {
console.error("We couldn't recognize your command -- perhaps try being more explicit?");
process.exit(1);
}
if (suggestion.commitMessage) {
const quantified = suggestion.commitMessage == 1 ? "a small summary" : "small summaries";
console.log(`Write ${quantified} of your changes: `);
let messages = [];
for (let i = 0; i < suggestion.commitMessage; i++) {
messages.push(question(`${i + 1} > `));
}
execute(suggestion.commands.map(c => {
if (c.includes("$MESSAGE")) {
return c.replace("$MESSAGE", messages.shift());
}
return c;
}));
} else {
execute(suggestion.commands);
}
}
main();