imq-cli
Version:
Command Line Interface for IMQ
48 lines • 1.76 kB
JavaScript
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
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',
builder(yargs) {
PROGRAM = 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 = lib_1.resolve(rcFilename);
if (fs_1.existsSync(rcFile)) {
const rcText = fs_1.readFileSync(rcFile, { encoding: 'utf8' })
.replace(RX_REPLACE, '')
.trim() + '\n';
fs_1.writeFileSync(rcFile, rcText, { encoding: 'utf8' });
}
printSuccess(rcFilename);
}
catch (err) {
lib_1.printError(err);
}
}
}, exports.command = _a.command, exports.describe = _a.describe, exports.builder = _a.builder, exports.handler = _a.handler;
//# sourceMappingURL=off.js.map
;