UNPKG

kui-shell

Version:

This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool

69 lines 3.13 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const i18n_1 = require("@kui-shell/core/api/i18n"); const tables_1 = require("@kui-shell/core/api/tables"); const strings = i18n_1.i18n('plugin-k8s'); const usage = { context: (command) => ({ command, strict: command, docs: 'Print your current kubernetes context', example: 'kubectl context' }), contexts: (command) => ({ command, strict: command, docs: 'List your available kubernetes contexts', example: 'kubectl contexts' }) }; const addClickHandlers = (table, { REPL }, execOptions) => { const body = table.body.map((row) => { const nameAttr = row.attributes.find(({ key }) => key === 'NAME'); const { value: contextName } = nameAttr; nameAttr.outerCSS += ' entity-name-group-narrow'; const onclick = () => __awaiter(void 0, void 0, void 0, function* () { yield REPL.qexec(`kubectl config use-context ${REPL.encodeComponent(contextName)}`, undefined, undefined, Object.assign({}, execOptions, { raw: true })); row.setSelected(); }); row.name = contextName; row.onclick = onclick; nameAttr.onclick = onclick; return row; }); return new tables_1.default.Table({ header: table.header, body: body, title: strings('contextsTableTitle') }); }; const listContexts = (opts) => { const execOptions = Object.assign({}, opts.execOptions, { render: false }); return opts.REPL.qexec(`kubectl config get-contexts`, undefined, undefined, execOptions).then((contexts) => tables_1.default.isMultiTable(contexts) ? { tables: contexts.tables.map(context => addClickHandlers(context, opts, execOptions)) } : addClickHandlers(contexts, opts, execOptions)); }; exports.default = (commandTree) => { commandTree.listen('/context', ({ execOptions, REPL }) => __awaiter(void 0, void 0, void 0, function* () { return (yield REPL.qexec(`kubectl config current-context`, undefined, undefined, Object.assign({}, execOptions, { raw: true }))).trim(); }), { usage: usage.context('context'), inBrowserOk: true }); commandTree.listen('/contexts', listContexts, { usage: usage.contexts('contexts'), width: 1024, height: 600, inBrowserOk: true }); }; //# sourceMappingURL=contexts.js.map