@controlplane/cli
Version:
Control Plane Corporation CLI
76 lines • 2.41 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompletionCommand = void 0;
const fs = require("fs");
const command_1 = require("./command");
const completer_1 = require("./completion/completer");
function dump(obj) {
if (process.env.CPLN_DEBUG) {
const path = '/tmp/complete-debug.json';
try {
fs.writeFileSync(path, JSON.stringify(obj, undefined, 2));
}
catch (_a) { }
}
}
class CompletionCommand extends command_1.Command {
constructor() {
super(...arguments);
this.command = 'completion';
this.describe = false;
}
builder(yargs) {
return yargs;
}
async handle(args) {
// get a parser without handlers
// @ts-ignore
const parser = args._parser();
// get the line as string[]
// ignore the first 4 elements because:
// node main.js cpln completion --
const array = process.argv.slice(5);
// force the model to be populated:
// handler are disable and all error reporting is turned off - we just want the parser to do 1 pass
let currentArgs;
try {
parser.showHelpOnFail(false);
parser.exitProcess(false);
parser.fail(() => { });
parser.strict(false);
currentArgs = parser.parse(array);
}
catch (e) {
// console.log(e);
}
// get the model from the spying instance
const stack = parser['_command_stack'];
const tabtabMod = require('tabtab');
const env = tabtabMod.parseEnv(process.env);
// dump env to
await this.complete(args, stack, env);
}
async complete(args, stack, env) {
const c = new completer_1.Completer(args, stack, env, this.env.profileManager);
try {
const completions = await c.complete();
dump({
env: env,
args: args,
stack: stack,
completions: completions,
});
const tabtabMod = require('tabtab');
tabtabMod.log(completions);
}
catch (e) {
dump({
env: env,
stack: stack,
error: e,
});
}
}
}
exports.CompletionCommand = CompletionCommand;
//# sourceMappingURL=complete.js.map
;