UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

82 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HelperCli = void 0; const yargs = require("yargs/yargs"); const version_1 = require("../util/version"); const logger_1 = require("../util/logger"); const format_1 = require("../format/format"); const cmds = require("./commands"); class HelperCli { constructor(env) { this.env = env; this.env = env; } makeParser() { const parser = yargs() .epilog('Control Plane Corporation') .help(false) .strict() .version(JSON.stringify(version_1.About, null, 2)) .detectLocale(false) .wrap(require('yargs').terminalWidth()) .parserConfiguration({ 'sort-commands': true, 'strip-aliased': true, 'parse-numbers': false, 'populate--': true, }) .recommendCommands() .demandCommand() .scriptName('docker-credential-cpln'); this.configure(parser); return parser; } configure(parser) { // add root commands here parser // https://github.com/docker/docker-credential-helpers/blob/master/credentials/credentials.go#L68 .command(new cmds.Get().toYargs()) .command(new cmds.Store().toYargs()) .command(new cmds.Erase().toYargs()) // .command(new cmds.List().toYargs()) .command(new cmds.Version().toYargs()); } run(args) { const parser = this.makeParser(); // properties will be put in the args object const ctx = { _env: this.env, }; // try to set the verbose flag early parser.middleware((args) => { if (args.verbose || process.env.CPLN_DEBUG) { // bump the console level logger_1.logger.transports[0].level = 'debug'; } }, true); parser.showHelpOnFail(false); const handler = (msg, e, yargs) => { if (e) { (0, format_1.write)(this.env.err, e.message + '\n'); process.exit(1); } // bad command if (msg) { console.error(msg + '\n'); } if (yargs) { console.error(yargs.help()); } process.exit(127); }; parser.fail(handler); try { parser.parse(args, ctx); } catch (e) { handler('', e, undefined); } } } exports.HelperCli = HelperCli; //# sourceMappingURL=cli.js.map