UNPKG

gitmate-cli

Version:

An AI-powered Git assistant that helps you with Git commands using natural language

41 lines (40 loc) • 1.4 kB
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); } }