UNPKG

use-multiple-gits

Version:

CLI tool to manage multiple git configurations (user.name, user.email, SSH keys) with easy switching between identities

66 lines 2.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeCommand = void 0; const inquirer_1 = __importDefault(require("inquirer")); const chalk_1 = __importDefault(require("chalk")); const configStorage_1 = require("../utils/configStorage"); const zshrc_1 = require("../utils/zshrc"); const fs_1 = require("../utils/fs"); const errors_1 = require("../utils/errors"); const removeCommand = async (name) => { try { if (!name) { console.log(chalk_1.default.red('Error: Configuration name is required')); console.log(chalk_1.default.yellow('Usage: multiGit remove <name>')); process.exit(1); } const initialized = await (0, configStorage_1.isInitialized)(); if (!initialized) { console.log(chalk_1.default.yellow('⚠️ Multi-Git not initialized.\n')); return; } const config = await (0, configStorage_1.getConfig)(name); if (!config) { throw new errors_1.ConfigNotFoundError(name); } const { confirm } = await inquirer_1.default.prompt([ { type: 'confirm', name: 'confirm', message: `Remove configuration "${name}"?`, default: false, }, ]); if (!confirm) { console.log(chalk_1.default.yellow('Cancelled.')); return; } const scriptPath = (0, fs_1.getScriptPath)(name); await (0, fs_1.removeFile)(scriptPath); console.log(chalk_1.default.green(`✅ Removed script: ${scriptPath}`)); await (0, configStorage_1.removeConfig)(name); await (0, zshrc_1.removeAlias)(name); const allConfigs = await (0, configStorage_1.getAllConfigs)(); if (allConfigs.length > 0) { await (0, zshrc_1.addAliases)(allConfigs); } console.log(chalk_1.default.green(`\n✅ Configuration "${name}" removed successfully!\n`)); } catch (error) { if (error instanceof errors_1.ConfigNotFoundError) { console.error(chalk_1.default.red(`\n❌ ${error.message}\n`)); } else if (error instanceof errors_1.FileSystemError) { console.error(chalk_1.default.red(`\n❌ ${error.message}\n`)); } else { console.error(chalk_1.default.red(`\n❌ Error: ${error.message}\n`)); } process.exit(1); } }; exports.removeCommand = removeCommand; //# sourceMappingURL=remove.js.map