gitmate-cli
Version:
An AI-powered Git assistant that helps you with Git commands using natural language
41 lines (40 loc) ⢠1.4 kB
JavaScript
import { spawn } from "child_process";
import { promptForCommandOptions } from "./inquirer.js";
export async function handleCommandOptions(command) {
// Clear the processing animation
process.stdout.write("\r" + " ".repeat(50) + "\r");
console.log(`\nš¤ ${command}\n`);
const action = await promptForCommandOptions();
switch (action) {
case "run":
await executeCommand(command);
break;
case "cancel":
console.log("\nš Cancelled. Ready for next command.");
break;
}
}
export async function executeCommand(command) {
console.log("\nš Executing command...\n");
const [cmd, ...args] = command.split(" ");
const child = spawn(cmd, args, {
stdio: "inherit",
shell: true,
});
child.on("close", (code) => {
if (code === 0) {
console.log(`\nā
Command completed successfully`);
}
else {
console.log(`\nā Command failed with exit code ${code}`);
console.log("š” You may need to modify the command or check your git repository state.");
}
});
}
// Check if it's the "I'm sorry" message, if it is, exit process. works for now haha
export function validateCommand(command) {
if (command.toLowerCase().includes("i'm sorry")) {
console.log(`\n${command}`);
process.exit(0);
}
}