UNPKG

kui-shell

Version:

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

50 lines 2.69 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 debug_1 = require("debug"); const capabilities_1 = require("@kui-shell/core/api/capabilities"); const debug = debug_1.default('plugins/bash-like/cmds/catchall'); exports.dispatchToShell = ({ tab, block, command, argvNoOptions, execOptions, parsedOptions, createOutputStream }) => __awaiter(void 0, void 0, void 0, function* () { const cleanUpError = (err) => { if (err.message && typeof err.message === 'string') { err.message = err.message.replace(/[a-zA-Z0-9/]+:\s*/, '').trim(); } throw err; }; const eOptions = execOptions.raw || execOptions.isProxied ? execOptions : Object.assign({}, { stdout: yield createOutputStream() }, execOptions); if (capabilities_1.default.isHeadless() || (!capabilities_1.default.inBrowser() && execOptions.raw)) { const { doExec } = yield Promise.resolve().then(() => require('./bash-like')); const response = yield doExec(command.replace(/^! /, ''), eOptions).catch(cleanUpError); if (execOptions.raw && typeof response === 'string') { try { return JSON.parse(response); } catch (err) { debug('response maybe is not JSON', response); } } return response; } else { const { doExec } = yield Promise.resolve().then(() => require('../../pty/client')); return doExec(tab, block, command.replace(/^(!|sendtopty)\s+/, ''), argvNoOptions, parsedOptions, eOptions).catch(cleanUpError); } }); exports.preload = (commandTree) => { if (capabilities_1.default.inBrowser() && !capabilities_1.default.hasProxy()) { debug('skipping catchall registration: in browser and no remote proxy to support it'); return; } return commandTree.catchall(() => true, exports.dispatchToShell, 0, { noAuthOk: true, inBrowserOk: true }); }; //# sourceMappingURL=catchall.js.map