UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

106 lines 4.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MiscCommand = void 0; const command_1 = require("./command"); const format_1 = require("../format/format"); class MiscCommand extends command_1.Command { constructor() { super(...arguments); this.command = 'misc'; this.describe = 'Miscellaneous helper commands'; } builder(yargs) { return yargs.demandCommand().command(new InstallCompletion().toYargs()).command(new UninstallCompletion().toYargs()); } handle() { } } exports.MiscCommand = MiscCommand; class InstallCompletion extends command_1.Command { constructor() { super(...arguments); this.command = 'install-completion'; this.describe = 'Install shell completion to your local profile'; } builder(yargs) { return yargs.options({ batch: { describe: 'Non-interactive (batch) mode', boolean: true, }, }); } async handle(args) { var _a, _b, _c; const zshInstallNote = 'Note: If you have installed the auto-completion to the zsh shell, make sure you have the following lines at the start of your ~/.zshrc file: \n\n autoload -U compinit\n compinit\n'; const noProfileNote = '\n\nTry creating a default profile first, using:\n\ncpln profile login\n'; const generalTroubleshootNote = '\n\nIf the installation failed, try:\n\t1. Restarting the shell\n\t2. (on mac) Installing rosetta with:\n\n\tsoftwareupdate --install-rosetta\n'; if (args.batch) { try { // XXX: reaching into tabtab internal to provide non-interactive install let installer = require('tabtab/lib/installer'); // deduce shell from environment, pick bash as a last resort let shell = ((_a = process.env.SHELL) === null || _a === void 0 ? void 0 : _a.replace(/.*\//, '')) || 'bash'; await installer.install({ name: 'cpln', completer: 'cpln', location: { bash: '~/.bashrc', zsh: '~/.zshrc', fish: '~/.config/fish/config.fish', }[shell], }); this.session.out(zshInstallNote); return; } catch (e) { const errorMessage = (_b = e.message) !== null && _b !== void 0 ? _b : ""; let errorNote = 'Error installing shell completion:\n\n' + errorMessage; if (errorMessage.includes('profile')) errorNote += noProfileNote; else errorNote += generalTroubleshootNote; (0, format_1.write)(this.env.err, errorNote); process.exit(1); } } try { await require('tabtab').install({ name: 'cpln', completer: 'cpln', }); this.session.out(zshInstallNote); } catch (e) { const errorMessage = (_c = e.message) !== null && _c !== void 0 ? _c : ""; let errorNote = 'Error installing shell completion:\n\n' + errorMessage; if (errorMessage.includes('profile')) errorNote += noProfileNote; else errorNote += generalTroubleshootNote; (0, format_1.write)(this.env.err, errorNote); process.exit(1); } } } class UninstallCompletion extends command_1.Command { constructor() { super(...arguments); this.command = 'uninstall-completion'; this.describe = 'Uninstall shell completion from your local profile'; } builder(yargs) { return yargs; } async handle() { try { await require('tabtab').uninstall({ name: 'cpln', }); } catch (e) { (0, format_1.write)(this.env.err, 'Error uninstalling shell completion'); process.exit(1); } } } //# sourceMappingURL=misc.js.map