UNPKG

@jashg91/gitpusher

Version:

šŸš€ AI-powered Git auto commit & push CLI with smart commit messages

102 lines (89 loc) • 3.61 kB
import chalk from "chalk"; import inquirer from "inquirer"; import { verifyAndSaveToken, deleteApiKeyFromDB } from "./apikey.js"; import { getLimitInfo, forceSyncCache } from "./usageTracker.js"; export async function handleConfigCommand() { console.log(chalk.cyan("\n╭─────────────────────────────────────╮")); console.log(chalk.cyan("│ āš™ļø GitPusher Config │")); console.log(chalk.cyan("╰─────────────────────────────────────╯\n")); const { action } = await inquirer.prompt([ { type: "list", name: "action", message: "What would you like to do?", choices: [ { name: chalk.green("šŸ”‘ Add Token"), value: "add" }, { name: chalk.blue("šŸ“Š View Usage Info"), value: "info" }, { name: chalk.cyan("šŸ”„ Sync Usage Cache"), value: "sync" }, { name: chalk.red("šŸ—‘ļø Delete Configuration"), value: "delete" }, { name: chalk.gray("āŒ Exit"), value: "exit" }, ], }, ]); if (action === "add") { await handleAddToken(); } else if (action === "info") { await handleViewInfo(); } else if (action === "sync") { await handleSyncCache(); } else if (action === "delete") { await handleDeleteKey(); } else { console.log(chalk.gray("\nšŸ‘‹ Exiting config...")); process.exit(0); } } async function handleAddToken() { const { token } = await inquirer.prompt([ { type: "input", name: "token", message: chalk.cyan("šŸ”‘ Enter your token: "), validate: (input) => (input ? true : "Token cannot be empty"), }, ]); await verifyAndSaveToken(token); } async function handleViewInfo() { const info = getLimitInfo(); if (!info) { console.log(chalk.red("\nāŒ No configuration found.")); console.log(chalk.yellow("šŸ’” Run 'gitpusher config' and add a token first.\n")); return; } console.log(chalk.cyan("\n╭─────────────────────────────────────╮")); console.log(chalk.cyan("│ šŸ“Š Usage Information │")); console.log(chalk.cyan("╰─────────────────────────────────────╯\n")); console.log(chalk.cyan("ā”œā”€ā”€ Token: ") + chalk.white(info.token)); console.log(chalk.cyan("ā”œā”€ā”€ API Key: ") + chalk.white(info.apikey)); console.log(chalk.cyan("└── Remaining Limit: ") + chalk.white(info.limit)); if (info.limit <= 10) { console.log(chalk.yellow("\nāš ļø Warning: Low usage limit remaining!")); } console.log(); } async function handleSyncCache() { console.log(chalk.cyan("\nšŸ”„ Attempting to sync cached usage data...\n")); await forceSyncCache(); console.log(); } async function handleDeleteKey() { const { confirm } = await inquirer.prompt([ { type: "confirm", name: "confirm", message: chalk.yellow("āš ļø Are you sure you want to delete your configuration?"), default: false, }, ]); if (confirm) { const result = await deleteApiKeyFromDB(); if (result) { console.log(chalk.green("\nāœ… Configuration deleted successfully!")); } else { console.log(chalk.red("\nāŒ Failed to delete configuration.")); } } else { console.log(chalk.gray("\nšŸ‘‹ Cancelled.")); } }