@imqueue/cli
Version:
Command Line Interface for IMQ
49 lines • 1.88 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.describe = exports.command = void 0;
const fs_1 = require("fs");
const lib_1 = require("../../lib");
const chalk_1 = require("chalk");
let PROGRAM = '';
let RX_REPLACE;
// istanbul ignore next
/**
* Prints script removal success message to the user
*
* @access private
* @param {string} rcFilename - path to shell rc file modified
*/
function printSuccess(rcFilename) {
process.stdout.write(chalk_1.default.green('Completions removed from ') +
chalk_1.default.cyan(`${rcFilename}`) + '\n' +
'To have these changes to take effect, please, run:\n\n' +
' $ ' + chalk_1.default.cyan(`source ${rcFilename}`) + '\n\n');
}
// noinspection JSUnusedGlobalSymbols
_a = {
command: 'off',
describe: 'Disables completions for this program in your shell',
async builder(yargs) {
PROGRAM = (await yargs.argv).$0;
RX_REPLACE = new RegExp(`###-begin-${PROGRAM}-completions-###`
+ '[\\s\\S]*?' + `###-end-${PROGRAM}-completions-###`);
},
handler() {
try {
const rcFilename = lib_1.IS_ZSH ? '~/.zshrc' : '~/.bashrc';
const rcFile = (0, lib_1.resolve)(rcFilename);
if ((0, fs_1.existsSync)(rcFile)) {
const rcText = (0, fs_1.readFileSync)(rcFile, { encoding: 'utf8' })
.replace(RX_REPLACE, '')
.trim() + '\n';
(0, fs_1.writeFileSync)(rcFile, rcText, { encoding: 'utf8' });
}
printSuccess(rcFilename);
}
catch (err) {
(0, lib_1.printError)(err);
}
}
}, exports.command = _a.command, exports.describe = _a.describe, exports.builder = _a.builder, exports.handler = _a.handler;
//# sourceMappingURL=off.js.map