How to use the @kui-shell/core.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-openwhisk / src / lib / cmds / activations / list.ts View on Github external
export default (commandTree: Commands.Registrar, wsk) => {
  if (!Capabilities.isHeadless()) {
    registerListView('activations', renderActivationListView)

    // for now, until we have updated the composer plugin
    registerListView('session', renderActivationListView)
  }

  wsk.synonyms('activations').forEach(syn => {
    commandTree.listen(`/wsk/${syn}/list`, doList(wsk), {
      usage: usage(syn).available.find(({ command }) => command === 'list')
    })
  })
}
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / beautify.ts View on Github external
({ execOptions, tab }) => {
        if (Capabilities.isHeadless()) {
          throw new Error('beautify not supported in headless mode')
        }

        const selection = currentSelection(tab)
        if (!selection) {
          throw new Error('You have not yet selected an entity')
        } else if (!(selection && selection.exec && selection.exec.code)) {
          throw new Error('no action code selected')
        } else {
          // beautify
          const beautify = require('js-beautify').js_beautify

          selection.exec.code = beautify(selection.exec.code)
          const code = getSidecar(tab).querySelector('.action-content .action-source') as HTMLElement
          code.innerText = selection.exec.code
github IBM / kui / plugins / plugin-openwhisk / src / lib / views / mode.ts View on Github external
mode !== 'default' &&
        !(
          selection[mode] ||
          (selection.exec && selection.exec[mode]) ||
          (isActivationSpec(selection) && selection.response[mode])
        )
      ) {
        throw new Error(`The current entity does not support viewing ${mode}`)
      } else {
        showSidecar(tab)
        return showEntity(tab, selection, { show: mode })
      }
    } else if (args.length === 3 || args.length === 4) {
      // activation logs xxx or wsk activation logs xxx
      const activation = await tab.REPL.qexec(`wsk ${entityType} get ${entityId}`)
      if (Capabilities.isHeadless()) {
        return activation[mode]
      } else {
        showEntity(tab, activation, { show: mode })
        return true // make repl happy
      }
    } else {
      const isVowel = c => c === 'a' || c === 'e' || c === 'i' || c === 'o' || c === 'u'
      const startsWithVowel = s => isVowel(s.charAt(0))

      throw new Error(
        !entityType
          ? 'You have not selected an entity'
          : `You have not yet selected ${startsWithVowel(entityType) ? 'an' : 'a'} ${entityType.replace(/s$/, '')}`
      )
    }
  }
github IBM / kui / plugins / plugin-apache-composer / src / lib / view / entity-view.ts View on Github external
export const visualizeComposition = async (tab: UI.Tab, response, execOptions) => {
  debug('Visualizing Composition', response)

  const action = response.message || response
  // const execOptions = opts.execOptions

  debug('execOptions', execOptions)

  if (hasAst(action) && !Capabilities.isHeadless()) {
    const doVisualize = execOptions.override || !execOptions.nested
    const options = execOptions.originalOptions || {}
    // use require rather than import here to prevent from prequiring wskflow module in headless mode
    const input = `/${response.namespace}/${response.name}`
    const { content, subtext } = await decorateAsApp(tab, {
      action,
      input,
      doVisualize,
      options: Object.assign({}, execOptions, options)
    })

    if (doVisualize) {
      debug('visualze composition')

      return Object.assign(action, {
        type: 'custom',
github IBM / kui / plugins / plugin-openwhisk / src / views.ts View on Github external
export default () => {
  if (!Capabilities.isHeadless()) {
    registerCLIEntityView('activations', async (
      tab: UI.Tab,
      response: Entity,
      resultDom: Element,
      parsedOptions: Object, // eslint-disable-line @typescript-eslint/ban-types
      execOptions: Object // eslint-disable-line @typescript-eslint/ban-types
    ) => {
      const showActivation = (await import('./lib/views/cli/activations/entity')).default as ViewHandler
      return showActivation(tab, response, resultDom, parsedOptions, execOptions)
    })

    const doShow = async (
      tab: UI.Tab,
      entity: Object, // eslint-disable-line @typescript-eslint/ban-types
      sidecar: Element,
      options: ShowOptions
github IBM / kui / plugins / plugin-k8s / src / lib / util / fetch-file.ts View on Github external
return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest()
      xhr.open(method, url)
      xhr.addEventListener('error', () => {
        console.error('error in xhr', xhr)
        reject(xhr.response || 'Internal Error')
      })
      xhr.addEventListener('load', () => {
        resolve({
          statusCode: xhr.status,
          body: xhr.response.response
        })
      })
      xhr.send()
    })
  } else if (Capabilities.isHeadless()) {
    debug('fetch via needle')
    const needle = await import('needle')
    return needle(method, url, { follow_max: 10 }).then(_ => ({ statusCode: _.statusCode, body: _.body }))
  } else {
    debug('fetch via electron.net')
    const { net } = (await import('electron')).remote

    return new Promise((resolve, reject) => {
      const request = net.request({
        method,
        url,
        redirect: 'follow'
      })

      request.on('response', response => {
        const statusCode = response.statusCode
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / wipe.ts View on Github external
const clean = (command: Commands.Arguments, type: string, quiet?: boolean) => {
  if (!quiet) {
    if (Capabilities.isHeadless()) {
      process.stdout.write('.'['random'])
    } else {
      debug(`Cleaning ${type}`)
    }
  }
  return list(command, type).then(deleteAllUntilDone(command, type))
}
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
const addWskflow = (tab: UI.Tab) => opts => {
  debug('addWskflow', opts)

  if (Capabilities.isHeadless()) return opts

  const { getEntity, editor, content, eventBus } = opts
  const wskflowContainer = document.createElement('div')
  const editorDom = content.querySelector('.monaco-editor-wrapper')

  content.appendChild(wskflowContainer)
  wskflowContainer.className = 'wskflow-container'

  /** update the view to show the latest AST */
  let lock
  const updateView = async (_?, { event = 'init' } = {}) => {
    if (lock) return
    else lock = true

    try {
      const action = getEntity()
github IBM / kui / plugins / plugin-apache-composer / src / lib / view / entity-view.ts View on Github external
export const formatCompositionEntity = ({ REPL, execOptions }: Commands.Arguments) => response => {
  return Capabilities.isHeadless()
    ? response
    : REPL.qexec(`wsk app get "${response.name}"`, undefined, undefined, execOptions)
}