How to use @kui-shell/core - 10 common examples

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 / openwhisk-core.ts View on Github external
// paramValue = paramValue.replace(new RegExp(startQuote, 'g'), '')
  }

  if (paramValue.charAt(0) === '$') {
    paramValue = process.env[paramValue]
  }

  if (paramValue.charAt(0) === '@') {
    // this is an @file form of parameter. read in the file
    // !!!!!!! FIXME cap the size of the file to avoid bombing out
    if (paramValue.charAt(1) === '$') {
      debug('filename from env var', paramValue.substring(2))
      paramValue = `@${process.env[paramValue.substring(2)]}`
    }

    const location = Util.expandHomeDir(paramValue.substring(1))
    if (!existsSync(location)) {
      throw new Error(`Requested parameter @file does not exist: ${location}`)
    } else {
      const extension = location.substring(location.lastIndexOf('.') + 1)
      const encoding = isBinary[extension] ? 'base64' : 'utf8'
      debug('encoding', encoding)

      paramValue = readFileSync(location).toString(encoding)
    }
  }

  // see if the value is JSON
  try {
    paramValue = JSON.parse(paramValue)
  } catch (e) {
    // console.error('NOT JSON', paramValue, typeof paramValue, argv)
github IBM / kui / plugins / plugin-core-support / src / lib / new-tab.ts View on Github external
const perTabInit = (tab: Tab, tabButton: HTMLElement, doListen = true) => {
  tab.state = new TabState()

  const newTabId = uuid()
  tab.setAttribute('data-tab-id', newTabId)
  tabButton.setAttribute('data-tab-id', newTabId)
  tabButton.onclick = () => switchTab(newTabId)

  setTimeout(async () => {
    getReplImpl(tab)
    eventBus.emit('/tab/new', tab)
  })

  if (doListen) {
    listen(getCurrentPrompt(tab))
  }

  // keep repl prompt focused, if possible
  const grabFocus = (checkPath: boolean) => (evt: MouseEvent) => {
    const target = evt.target
    if (isElement(target)) {
      setTimeout(() => {
        const prompt = getCurrentPrompt(tab)
        if (
          prompt &&
          getSelectionText().length === 0 &&
          (target.classList.contains('repl-inner') ||
            target.classList.contains('repl-output') ||
            target.classList.contains('kui--tab-navigatable') ||
            (checkPath && evt['path'] && evt['path'].find(_ => isElement(_) && /header/i.test(_.tagName))))
        ) {
github IBM / kui / plugins / plugin-core-support / src / lib / new-tab.ts View on Github external
setStatus(currentlyProcessingBlock, Status.replActive)
  }

  // this must occur after the REPL.qexec('clear'), otherwise we may select
  // the wrong repl-result
  empty(newTab.querySelector('.repl-result'))

  clearSelection(newTab)
  perTabInit(newTab, newTabButton)

  newTabButton.scrollIntoView()

  // make the new tab visible at the very end of the above init work!
  currentVisibleTab.classList.remove('visible')
  currentVisibleTab.parentNode.appendChild(newTab)
  getCurrentPrompt(newTab).focus()

  getTabButtonLabel(newTab).innerText = !isUsingCommandName() ? strings('Tab') : strings('New Tab')

  return true
}
github IBM / kui / plugins / plugin-k8s / src / lib / view / formatTable.ts View on Github external
rowIsSelected ? 'selected-row' : ''
      ]

      // if there isn't a global namespace specifier, maybe there is a row namespace specifier
      // we use the row specifier in preference to a global specifier -- is that right?
      const ns =
        (namespaceColumnIdx >= 0 && command !== 'helm' && `-n ${encodeComponent(rows[namespaceColumnIdx].value)}`) ||
        drilldownNamespace ||
        ''

      // idx === 0: don't click on header row
      const onclick =
        idx === 0
          ? false
          : drilldownVerb
          ? `${drilldownCommand} ${drilldownVerb}${drilldownKind(nameSplit, rows)} ${encodeComponent(
              nameForDrilldown
            )} ${drilldownFormat} ${ns}`
          : false

      const header = idx === 0 ? 'header-cell' : ''

      // for `k get events`, show REASON and MESSAGE columns when sidecar open
      const columnVisibleWithSidecar = new RegExp(/STATUS|REASON|MESSAGE/i)

      // show red-background if it's a failure reason in `k  get events`
      const maybeRed = (reason: string) => {
        return /failed/i.test(reason) ? 'red-background' : ''
      }

      return {
        key: rows[0].key,
github IBM / kui / plugins / plugin-k8s / src / lib / controller / kubectl.ts View on Github external
const status = async (command: string, code?: number, stderr?: string) => {
      if (hasFileArg || verb === 'delete' || verb === 'create') {
        if (!execOptions.noStatus) {
          const expectedState = verb === 'create' || verb === 'apply' ? FinalState.OnlineLike : FinalState.OfflineLike
          const finalState = `--final-state ${expectedState.toString()}`
          const resourceNamespace =
            options.n || options.namespace ? `-n ${encodeComponent(options.n || options.namespace)}` : ''

          debug('about to get status', file, entityType, entity, resourceNamespace)
          return REPL.qexec(
            `${statusCommand} status ${file || entityType} ${entity || ''} ${finalState} ${resourceNamespace} --watch`,
            undefined,
            undefined,
            { parameters: execOptions.parameters }
          ).catch(err => {
            if (err.code === 404 && expectedState === FinalState.OfflineLike) {
              // that's ok!
              debug('resource not found after status check, but that is ok because that is what we wanted')
              return out
            } else {
              console.error('error constructing status', err)
              return err
            }
github IBM / kui / plugins / plugin-openwhisk / src / lib / views / sidecar / entity.ts View on Github external
if (annotation.badge && annotation.badge !== 'web') {
            // render a badge, if we have one; we render web badges specially, with maybeAddWebBadge
            addBadge(tab, annotation.badge)
          }

          return true // yes, we took care of the rendering!
        }

        return renderingTakenCareOf
      }, false)
    }
  } // end of third party view mod

  // const content = sidecar.querySelector('.sidecar-content')
  if (entity.exec) {
    const kind = element('.action-content .kind', sidecar)
    if (entity.exec.kind) {
      const kindText = entity.exec.prettyKind || entity.exec.kind
      const kindBits = kindText.split(/:/) // nodejs:6 => ['nodejs', '6']
      kind.innerText = kindBits[0]
      if (entity.exec.prettyKind === 'app') {
        kind.innerText = `This entity represents a composition`
      } else if (entity.exec.kind === 'source') {
        kind.innerText = `This is a preview of your app, it is not yet deployed`
      } else {
        kind.innerText = `This is a ${kindText} action`
      }
    } else {
      kind.innerText = ''
    }

    /* const url = sidecar.querySelector('.entity-web-export-url')
github IBM / kui / plugins / plugin-openwhisk / src / lib / views / sidecar / activations.ts View on Github external
0.000017 *
      1000000
    ).toFixed(2)
    element('.activation-estimated-cost', sidecar).innerText = roughCostEstimate
  }

  // the entity.namespace and entity.name of activation records don't include the package name :/
  const pathAnnotation = entity.annotations && entity.annotations.find(kv => kv.key === 'path')
  const entityNameWithPackageAndNamespace =
    (pathAnnotation && pathAnnotation.value) || `${entity.namespace}/${entity.name}`
  const pathComponents = pathAnnotation && entityNameWithPackageAndNamespace.split('/')
  const entityPackageName = pathComponents ? (pathComponents.length === 2 ? '' : pathComponents[1]) : '' // either ns/package/action or ns/action

  // make the nameDom clickable, traversing to the action
  const footer = sidecar.querySelector('.sidecar-bottom-stripe')
  element('.package-prefix', footer).innerText = entityPackageName
  const entityName = element('.entity-name', nameDom)
  entityName.innerText = entity.name
  entityName.className = `${entityName.className} clickable`
  entityName.onclick =
    entity.onclick ||
    (async () => {
      tab.REPL.pexec(`wsk action get "/${entityNameWithPackageAndNamespace}"`)
    })

  // add the activation id to the header
  const activationDom = element('.sidecar-header-name .entity-name-hash', sidecar)
  activationDom.innerText = entity.activationId

  // view mode
  const show =
    (options && options.show) || // cli-specified mode
github IBM / kui / plugins / plugin-core-support / src / lib / new-tab.ts View on Github external
const addCommandEvaluationListeners = (): void => {
  eventBus.on('/command/complete', (event: Event) => {
    if (event.execType !== undefined && event.execType !== ExecType.Nested && event.route) {
      // ignore nested, which means one plugin calling another
      // debug('got event', event)
      const button = getTabButton(event.tab)
      if (button) {
        // the tab might no longer be visible
        button.classList.remove('processing')
      }
    }
  })

  eventBus.on('/command/start', (event: Event) => {
    if (event.execType !== undefined && event.execType !== ExecType.Nested && event.route) {
      // ignore nested, which means one plugin calling another
      // debug('got event', event)

      const tab = event.tab

      if (
        event.route !== undefined &&
        !event.route.match(/^\/(tab|getting\/started)/) // ignore our own events and help
      ) {
        if (/^\/clear/.test(event.route)) {
          // nbsp in the case of clear, except if the sidecar is open;
          // then attempt to continue displaying the command that
          // produced the sidecar; TODO this isn't quite right; we
          // need to find a way to capture that sidecar-producing
          // command
github IBM / kui / plugins / plugin-wrk / src / lib / lt.ts View on Github external
pushResolve()
          } else if (N === iters) {
            console.error('Exiting due to maxIters')
            pushResolve()
          } else {
            // we're not terminating, so push the current result and continue
            push()
            iter(N + 1)
          }
        }
      )
    }

    iter(1, { dryRun: true })

    eventBus.on('/wrk/terminate', () => {
      terminateNow = true
    })
  })
    .then(result => {
github IBM / kui / plugins / plugin-bash-like / src / pty / client.ts View on Github external
terminal.open(xtermContainer)
          // webLinksInit(terminal)

          // theming
          // injectFont(terminal) // inject once on startup
          const doInjectTheme = () => injectFont(terminal, true)
          eventBus.on('/theme/change', doInjectTheme) // and re-inject when the theme changes

          resizer = new Resizer(terminal, tab, execOptions)

          // respond to font zooming
          const doZoom = () => {
            injectFont(terminal, true)
            resizer.resize()
          }
          eventBus.on('/zoom', doZoom)

          const cleanupEventHandlers = () => {
            eventBus.off('/zoom', doZoom)
            eventBus.off('/theme/change', doInjectTheme)
          }

          // heuristic for hiding empty rows
          terminal.element.classList.add('xterm-empty-row-heuristic')
          setTimeout(() => terminal.element.classList.remove('xterm-empty-row-heuristic'), 100)

          //
          // on exit, remove event handlers and the like
          //
          cleanUpTerminal = () => {
            cleanupEventHandlers()
            resizer.destroy()