Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (err) {
console.error('error rendering help', err)
reject(out)
}
} else if (output === 'json' || output === 'yaml' || verb === 'logs') {
//
// return a sidecar entity
//
debug('formatting structured output', output)
const result = output === 'json' ? JSON.parse(out) : verb === 'logs' ? formatLogs(out, execOptions) : out
// debug('structured output', result)
if (Capabilities.isHeadless() && execOptions.type === Commands.ExecType.TopLevel && !execOptions.isProxied) {
debug('directing resolving', Capabilities.isHeadless())
return cleanupAndResolve(result)
}
const modes: Mode[] = [
{
mode: 'result',
direct: rawCommand,
label: strings(
verb === 'describe' ? 'describe' : output === 'json' || output === 'yaml' ? output.toUpperCase() : output
),
defaultMode: true
}
]
if (verb === 'logs') {
const directCmd = rawCommand.replace(/^_kubectl(\s)?/, 'kubectl$1').replace(/^_k(\s)?/, 'kubectl$1')
cleanupAndResolve(renderHelp(out, command, verb, originalCode))
} catch (err) {
console.error('error rendering help', err)
reject(out)
}
} else if (output === 'json' || output === 'yaml' || verb === 'logs') {
//
// return a sidecar entity
//
debug('formatting structured output', output)
const result = output === 'json' ? JSON.parse(out) : verb === 'logs' ? formatLogs(out, execOptions) : out
// debug('structured output', result)
if (Capabilities.isHeadless() && execOptions.type === Commands.ExecType.TopLevel && !execOptions.isProxied) {
debug('directing resolving', Capabilities.isHeadless())
return cleanupAndResolve(result)
}
const modes: Mode[] = [
{
mode: 'result',
direct: rawCommand,
label: strings(
verb === 'describe' ? 'describe' : output === 'json' || output === 'yaml' ? output.toUpperCase() : output
),
defaultMode: true
}
]
if (verb === 'logs') {
// already exists or file not found?
const error: Errors.CodedError = new Error(err)
error.code = codeForREPL
debug('rejecting without usage', codeForREPL, error)
reject(error)
} else if ((verb === 'create' || verb === 'apply' || verb === 'delete') && hasFileArg) {
debug('fetching status after error')
status(command, codeForREPL, err)
.then(cleanupAndResolve)
.catch(reject)
} else {
nope()
}
} else if (
execOptions.raw ||
(Capabilities.isHeadless() &&
!output &&
!shouldWeDisplayAsTable(verb, entityType, output, options) &&
execOptions.type === Commands.ExecType.TopLevel &&
!execOptions.isProxied)
) {
//
// caller asked for the raw output
//
// debug('raw', output);
debug('resolving raw', argvWithFileReplacements.join(' '), output)
if (output === 'json') {
try {
const json = JSON.parse(out)
cleanupAndResolve(json.items || json)
} catch (err) {
console.error(err)
async function kubectl(opts: Commands.Arguments) {
const { REPL } = opts
const semi = await REPL.semicolonInvoke(opts)
if (semi) {
return semi
}
if (!Capabilities.isHeadless() && shouldSendToPTY(opts)) {
// execOptions.exec = 'REPL.qexec'
debug('redirect exec command to PTY')
const commandToPTY = opts.command.replace(/^k(\s)/, 'kubectl$1')
return REPL.qexec(
`sendtopty ${commandToPTY}`,
opts.block,
undefined,
Object.assign({}, opts.execOptions, { rawResponse: true })
)
} else if (!Capabilities.inBrowser() || opts.argvNoOptions[1] === 'summary') {
// debug('invoking _kubectl directly')
return _kubectl(opts)
} else {
// debug('invoking _kubectl via REPL.qexec')
const command = opts.command.replace(/^kubectl(\s)?/, '_kubectl$1').replace(/^k(\s)?/, '_kubectl$1')
return REPL.qexec(command, opts.block, undefined, {
export default async () => {
if (!Capabilities.isHeadless()) {
const { registerMode } = await import('@kui-shell/core/api/registrars')
Promise.all([
import('./lib/view/modes/pods')
.then(_ => _.podMode)
.then(registerMode), // show pods of deployments
import('./lib/view/modes/events')
.then(_ => _.eventsMode)
.then(registerMode), // show events
import('./lib/view/modes/containers')
.then(_ => _.containersMode)
.then(registerMode), // show containers of pods
import('./lib/view/modes/last-applied')
.then(_ => _.lastAppliedMode)
.then(registerMode), // show a last applied configuration tab
import('./lib/tab-completion')
.then(_ => _.default())
export default () => {
// register a "special path" that resolves
const specialPath = join(dirname(require.resolve('@kui-shell/plugin-tekton/package.json')), 'samples/@demos')
Util.augmentModuleLoadPath(specialPath, { prefix: '@demos/tekton', command: 'tekton flow' })
if (!isHeadless()) {
return registerModes()
}
}
//
// output format option
//
const output =
!options.help &&
(options.output ||
options.o ||
(command === 'helm' && verb === 'get' && 'yaml') || // helm get seems to spit out yaml without our asking
(isKube && verb === 'describe' && 'yaml') ||
(isKube && verb === 'logs' && 'latest') ||
(isKube && verb === 'get' && execOptions.raw && 'json'))
if (
!execOptions.raw &&
(!Capabilities.isHeadless() || execOptions.isProxied) &&
!execOptions.noDelegation &&
isKube &&
((verb === 'summary' || (verb === 'get' && (output === 'yaml' || output === 'json'))) &&
(execOptions.type !== Commands.ExecType.Nested || execOptions.delegationOk))
) {
debug('delegating to summary provider', execOptions.delegationOk, Commands.ExecType[execOptions.type].toString())
const describeImpl = (await import('./describe')).default
opts.argvNoOptions[0] = 'kubectl'
opts.argv[0] = 'kubectl'
opts.command = opts.command.replace(/^_kubectl/, 'kubectl')
return describeImpl(opts)
.then(resolve)
.catch(reject)
} else if (isKube && (verb === 'status' || verb === 'list')) {
return statusImpl(verb)(opts)
.then(resolve)
export default async (registrar: PreloadRegistrar) => {
if (!isHeadless()) {
;(await import('./non-headless-preload')).default(registrar)
}
}
export default async () => {
debug('initializing')
if (!Capabilities.isHeadless()) {
const { Models } = await import('@kui-shell/core/api/models')
const { persisters } = await import('./lib/cmds/new')
const getEntity = (tab: Tabs.Tab) => {
const entity = Models.Selection.current(tab)
entity['persister'] = persisters.actions
debug('getEntity', entity)
return entity
}
const { gotoReadonlyView, fetchAction } = await import('./lib/cmds/new')
registerFetcher(fetchAction())
const unlock = lockIcon({
getEntity,
export const setPleaseSelectNamespace = () => {
if (Capabilities.isHeadless()) {
return
}
const namespaceDom = document.querySelector('#openwhisk-namespace') as HTMLElement
namespaceDom.className += ' oops'
namespaceDom.innerText = 'please select a namespace'
namespaceDom.removeAttribute('data-value')
}