How to use the cli-ux.cli.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 / oauth / src / commands / authorizations / create.ts View on Github external
cli.action.start('Creating OAuth Authorization')

    const {body: auth} = await this.heroku.post('/oauth/authorizations', {
      body: {
        description: flags.description,
        scope: flags.scope ? flags.scope.split(',') : undefined,
        expires_in: flags['expires-in'],
      },
    })

    cli.action.stop()

    if (flags.short) {
      cli.log(auth.access_token && auth.access_token.token)
    } else if (flags.json) {
      cli.styledJSON(auth)
    } else {
      display(auth)
    }
  }
}
github heroku / cli / packages / ps / src / commands / regions.ts View on Github external
async run() {
    const {flags} = this.parse(Regions)
    let {body: regions} = await this.heroku.get('/regions')
    if (flags.private) {
      regions = regions.filter((region: any) => region.private_capable)
    } else if (flags.common) {
      regions = regions.filter((region: any) => !region.private_capable)
    }
    regions = _.sortBy(regions, ['private_capable', 'name'])

    if (flags.json) {
      cli.styledJSON(regions)
    } else {
      cli.table(regions, {
        columns: [
          {key: 'name', label: 'ID', format: (n: any) => color.green(n)},
          {key: 'description', label: 'Location'},
          {key: 'private_capable', label: 'Runtime', format: (c: any) => c ? 'Private Spaces' : 'Common Runtime'}
        ]
      })
    }
  }
}
github heroku / cli / packages / oauth / src / commands / authorizations / index.ts View on Github external
async run() {
    const {flags} = this.parse(AuthorizationsIndex)

    let {body: authorizations} = await this.heroku.get>('/oauth/authorizations')

    authorizations = sortBy(authorizations, 'description')

    if (flags.json) {
      cli.styledJSON(authorizations)
    } else if (authorizations.length === 0) {
      cli.log('No OAuth authorizations.')
    } else {
      cli.table(authorizations, {
        description: {get: (v: any) => color.green(v.description)},
        id: {},
        scope: {get: (v: any) => v.scope.join(',')},
      }, {'no-header': true, printLine: this.log})
    }
  }
}
github heroku / cli / packages / heroku-apps / src / commands / regions / index.js View on Github external
async run () {
    const sortBy = require('lodash.sortby')

    let {body: regions} = await this.heroku.get('/regions')
    if (this.flags.private) {
      regions = regions.filter(region => region.private_capable)
    } else if (this.flags.common) {
      regions = regions.filter(region => !region.private_capable)
    }
    regions = sortBy(regions, ['private_capable', 'name'])

    if (this.flags.json) {
      cli.styledJSON(regions)
    } else {
      cli.table(regions, {
        columns: [
          {key: 'name', label: 'ID', format: (n) => cli.color.green(n)},
          {key: 'description', label: 'Location'},
          {key: 'private_capable', label: 'Runtime', format: (c) => c ? 'Private Spaces' : 'Common Runtime'}
        ]
      })
    }
  }
}
github heroku / cli / packages / oauth / src / commands / clients / info.ts View on Github external
async run() {
    const {args, flags} = this.parse(ClientsInfo)

    const {body: client} = await this.heroku.get(`/oauth/clients/${args.id}`)

    if (flags.json) {
      cli.styledJSON(client)
    } else if (flags.shell) {
      cli.log(`HEROKU_OAUTH_ID=${client.id}`)
      cli.log(`HEROKU_OAUTH_SECRET=${client.secret}`)
    } else {
      cli.styledHeader(`${client.name}`)
      cli.styledObject(client)
    }
  }
}
github heroku / cli / packages / oauth / src / commands / clients / create.ts View on Github external
async run() {
    const {args, flags} = this.parse(ClientsCreate)

    const {redirect_uri, name} = args
    validateURL(redirect_uri)

    cli.action.start(`Creating ${args.name}`)

    const {body: client} = await this.heroku.post('/oauth/clients', {
      body: {name, redirect_uri},
    })

    cli.action.stop()

    if (flags.json) {
      cli.styledJSON(client)
    } else {
      cli.log(`HEROKU_OAUTH_ID=${client.id}`)
      cli.log(`HEROKU_OAUTH_SECRET=${client.secret}`)
    }
  }
}
github heroku / cli / packages / webhooks / src / commands / webhooks / deliveries / info.ts View on Github external
Event: delivery.event.id,
      Webhook: delivery.webhook.id,
      Status: delivery.status,
      Include: delivery.event.include,
      Level: delivery.webhook.level,
      Attempts: delivery.num_attempts,
      Code: delivery.last_attempt && delivery.last_attempt.code,
      Error: delivery.last_attempt && delivery.last_attempt.error_class,
      'Next Attempt': delivery.next_attempt_at
    }

    cli.styledHeader(delivery.id)
    cli.styledObject(obj)

    cli.styledHeader('Event Payload')
    cli.styledJSON(event.payload)
  }
}
github heroku / cli / packages / oauth / src / commands / authorizations / info.ts View on Github external
async run() {
    const {args, flags} = this.parse(AuthorizationsInfo)

    const {body: authentication} = await this.heroku.get(
      `/oauth/authorizations/${args.id}`,
    )

    if (flags.json) {
      cli.styledJSON(authentication)
    } else {
      display(authentication)
    }
  }
}
github heroku / cli / packages / oauth / src / commands / clients / rotate.ts View on Github external
async run() {
    const {args, flags} = this.parse(ClientsRotate)

    cli.action.start(`Updating ${color.cyan(args.id)}`)

    const {body: client} = await this.heroku.post(
      `/oauth/clients/${encodeURIComponent(args.id)}/actions/rotate-credentials`,
    )

    cli.action.stop()

    if (flags.json) {
      cli.styledJSON(client)
    } else if (flags.shell) {
      cli.log(`HEROKU_OAUTH_ID=${client.id}`)
      cli.log(`HEROKU_OAUTH_SECRET=${client.secret}`)
    } else {
      cli.styledHeader(`${client.name}`)
      cli.styledObject(client)
    }
  }
}