How to use the @kui-shell/core/api/capabilities.isHeadless function in @kui-shell/core

To help you get started, we’ve selected a few @kui-shell/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
} 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')
github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
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') {
github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
// 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)
github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
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, {
github IBM / kui / plugins / plugin-k8s / src / preload.ts View on Github external
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())
github IBM / kui / plugins / plugin-tekton / src / preload.ts View on Github external
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()
  }
}
github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
//
    // 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)
github IBM / kui / plugins / plugin-operator-framework / src / preload.ts View on Github external
export default async (registrar: PreloadRegistrar) => {
  if (!isHeadless()) {
    ;(await import('./non-headless-preload')).default(registrar)
  }
}
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / preload.ts View on Github external
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,
github IBM / kui / plugins / plugin-openwhisk / src / lib / models / namespace.ts View on Github external
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')
}