How to use the cli-ux.styledJSON function in cli-ux

To help you get started, we’ve selected a few cli-ux 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 heroku / cli / packages / apps / src / commands / domains / add.ts View on Github external
const domainCreatePayload: DomainCreatePayload = {
      hostname
    }

    if (featureFlag.enabled) {
      // multiple SNI endpoints is enabled
      if (flags.cert) {
        domainCreatePayload.sni_endpoint = flags.cert
      }
    }

    try {
      const domain = await this.createDomain(flags.app, domainCreatePayload)
      if (flags.json) {
        cli.styledJSON(domain)
      } else {
        cli.log(`Configure your app's DNS provider to point to the DNS Target ${color.green(domain.cname || '')}.
  For help, see https://devcenter.heroku.com/articles/custom-domains`)
        if (domain.status !== 'none') {
          if (flags.wait) {
            await waitForDomain(flags.app, this.heroku, domain)
          } else {
            cli.log('')
            cli.log(`The domain ${color.green(hostname)} has been enqueued for addition`)
            let command = `heroku domains:wait ${shellescape([hostname])}`
            cli.log(`Run ${color.cmd(command)} to wait for completion`)
          }
        }
      }
    } catch (err) {
      cli.error(err)
github heroku / cli / packages / ci / src / utils / test-run.ts View on Github external
function draw(testRuns: Heroku.TestRun[], watchOption = false, jsonOption = false, count = 15) {
  const latestTestRuns = sort(testRuns).slice(0, count)

  if (jsonOption) {
    cli.styledJSON(latestTestRuns)
    return
  }

  if (watchOption) {
    process.stdout.write(ansiEscapes.eraseDown)
  }

  let data: any = []

  latestTestRuns.forEach(testRun => {
    data.push(
      {
        iconStatus: `${statusIcon(testRun)}`,
        number: testRun.number,
        branch: testRun.commit_branch,
        sha: testRun.commit_sha!.slice(0, 7),
github heroku / cli / packages / apps / src / commands / domains / index.ts View on Github external
async run() {
    const {flags} = this.parse(DomainsIndex)
    const {body: domains} = await this.heroku.get>(`/apps/${flags.app}/domains`)
    const herokuDomain = domains.find(domain => domain.kind === 'heroku')
    const customDomains = domains.filter(domain => domain.kind === 'custom')

    if (flags.json) {
      cli.styledJSON(domains)
    } else {
      cli.styledHeader(`${flags.app} Heroku Domain`)
      cli.log(herokuDomain && herokuDomain.hostname)
      if (customDomains && customDomains.length > 0) {
        cli.log()
        cli.styledHeader(`${flags.app} Custom Domains`)
        cli.table(customDomains, {
          hostname: {header: 'Domain Name'},
          kind: {header: 'DNS Record Type', get: domain => {
            if (domain.hostname) {
              return isApexDomain(domain.hostname) ? 'ALIAS or ANAME' : 'CNAME'
            }
          }},
          cname: {header: 'DNS Target'},
          acm_status: {header: 'ACM Status', extended: true},
          acm_status_reason: {header: 'ACM Status', extended: true}
github heroku / heroku-api-plugin / src / commands / api.ts View on Github external
throw err
      }
      let msg = color`{greenBright ${response.response!.statusCode!.toString()}}`
      if (Array.isArray(response.body)) msg += ` ${response.body.length + body.length} items`
      cli.action.stop(msg)
      if (Array.isArray(response.body) && response.response.headers['next-range']) {
        request.headers!.range = response.response.headers['next-range']
        return fetch(body.concat(response.body))
      }
      return Array.isArray(response.body) ? body.concat(response.body) : response.body
    }
    let body = await fetch()
    if (typeof body === 'string') {
      cli.log(body)
    } else {
      cli.styledJSON(body)
    }
  }
}
github optimizely / javascript-sdk / packages / eet_validation / src / commands / datafile.ts View on Github external
async run() {
    const datafile = await this.fetchDatafile()
    cli.styledJSON(datafile)

    const optimizely = await this.optimizelyClient()
  }
}
github heroku / cli / packages / status / src / commands / status.ts View on Github external
const capitalize = (str: string) => str.substr(0, 1).toUpperCase() + str.substr(1)
    const printStatus = (status: string) => {
      const colorize = (color as any)[status]
      let message = capitalize(status)

      if (status === 'green') {
        message = 'No known issues at this time.'
      }
      return colorize(message)
    }

    let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com'
    let {body} = await HTTP.get(host + apiPath)

    if (flags.json) {
      cli.styledJSON(body)
      return
    }

    for (let item of body.status) {
      let message = printStatus(item.status)

      this.log(`${(item.system + ':').padEnd(11)}${message}`)
    }

    for (let incident of body.incidents) {
      cli.log()
      cli.styledHeader(`${incident.title} ${color.yellow(incident.created_at)} ${color.cyan(incident.full_url)}`)

      let padding = maxBy(incident.updates, (i: any) => i.update_type.length).update_type.length + 0
      for (let u of incident.updates) {
        cli.log(`${color.yellow(u.update_type.padEnd(padding))} ${new Date(u.updated_at).toISOString()} (${distanceInWordsToNow(new Date(u.updated_at))} ago)`)
github optimizely / javascript-sdk / packages / eet_validation / src / commands / activate.ts View on Github external
const {flags} = this.parse(Activate)

    const opti = await this.optimizelyClient()

    cli.action.start('Performing activate')

    const decision = opti.activate(
      flags.experiment,
      flags.user,
      this.userAttributes
    )

    cli.action.stop()

    cli.styledHeader('Result')
    cli.styledJSON(decision)
  }
github heroku / cli / packages / pipelines / src / commands / pipelines / index.ts View on Github external
async run() {
    const {flags} = this.parse(Pipelines)

    const {body: pipelines} = await this.heroku.get('/pipelines')

    if (flags.json) {
      cli.styledJSON(pipelines)
    } else {
      cli.styledHeader('My Pipelines')
      for (const pipeline of pipelines) {
        cli.log(pipeline.name)
      }
    }
  }
}
github heroku / cli / src / subject_command.ts View on Github external
if (format !== 'json') val = inspect(val, {breakLength: Infinity})
        _.set(row, col.key, val)
      }
      return row
    })
    if (sort) {
      arr = _.sortBy(arr, row => {
        let prop = Object
        .entries(row)
        .find(([k]) => k.toLowerCase() === sort.toLowerCase())
        if (prop) return prop[1]
      })
    }
    switch (format) {
      case 'json':
        return ux.styledJSON(arr)
      case 'csv':
        return this.csv(arr)
      case 'table':
      default:
        this.table(arr, columns, options)
    }
  }
github heroku / cli / packages / config / src / commands / config / index.ts View on Github external
async run() {
    const {flags} = this.parse(ConfigIndex)
    const {body: config} = await this.heroku.get(`/apps/${flags.app}/config-vars`)
    if (flags.shell) {
      Object.entries(config)
        .forEach(([k, v]) => ux.log(`${k}=${quote(v)}`))
    } else if (flags.json) {
      ux.styledJSON(config)
    } else {
      ux.styledHeader(`${flags.app} Config Vars`)
      ux.styledObject(_.mapKeys(config, (_, k) => color.configVar(k)))
    }
  }
}