<commit_before>'use strict'

const cli = require('heroku-cli-util')
const co = require('co')
const {flags} = require('cli-engine-heroku')

function display (spaces) {
  cli.table(spaces, {
    columns: [
      {key: 'name', label: 'Name'},
      {key: 'organization.name', label: 'Organization'},
      {key: 'region.name', label: 'Region'},
      {key: 'state', label: 'State'},
      {key: 'created_at', label: 'Created At'}
    ]
  })
}

function displayJSON (spaces) {
  cli.log(JSON.stringify(spaces, null, 2))
}

function * run (context, heroku) {
  const sortBy = require('lodash.sortby')
  let team = context.org || context.team || context.flags.team

  let spaces = yield heroku.get('/spaces')
  if (team) {
    spaces = spaces.filter((s) => s.organization.name === team)
  }
  spaces = sortBy(spaces, 'name')
  if (context.flags.json) displayJSON(spaces)
  else if (spaces.length === 0) {
    if (team) throw new Error(`No spaces in ${cli.color.cyan(team)}.`)
    else throw new Error('You do not have access to any spaces.')
  } else {
    display(spaces)
  }
}

module.exports = {
  topic: 'spaces',
  description: 'list available spaces',
  needsAuth: true,
  flags: [
    {name: 'json', description: 'output in json format'},
    flags.org({name: 'org', hasValue: true}),
    flags.team({name: 'team', hasValue: true, required: true})
  ],
  run: cli.command(co.wrap(run))
}<commit_msg>Remove required --team on spaces cmd (#40)<commit_after>'use strict'

const cli = require('heroku-cli-util')
const co = require('co')
const {flags} = require('cli-engine-heroku')

function display (spaces) {
  cli.table(spaces, {
    columns: [
      {key: 'name', label: 'Name'},
      {key: 'organization.name', label: 'Organization'},
      {key: 'region.name', label: 'Region'},
      {key: 'state', label: 'State'},
      {key: 'created_at', label: 'Created At'}
    ]
  })
}

function displayJSON (spaces) {
  cli.log(JSON.stringify(spaces, null, 2))
}

function * run (context, heroku) {
  const sortBy = require('lodash.sortby')
  let team = context.org || context.team || context.flags.team

  let spaces = yield heroku.get('/spaces')
  if (team) {
    spaces = spaces.filter((s) => s.organization.name === team)
  }
  spaces = sortBy(spaces, 'name')
  if (context.flags.json) displayJSON(spaces)
  else if (spaces.length === 0) {
    if (team) throw new Error(`No spaces in ${cli.color.cyan(team)}.`)
    else throw new Error('You do not have access to any spaces.')
  } else {
    display(spaces)
  }
}

module.exports = {
  topic: 'spaces',
  description: 'list available spaces',
  needsAuth: true,
  flags: [
    {name: 'json', description: 'output in json format'},
    flags.org({name: 'org', hasValue: true}),
    flags.team({name: 'team', hasValue: true})
  ],
  run: cli.command(co.wrap(run))
}
{'fraction_non_alphanumeric': 0.17739068610024886, 'fraction_numerical': 0.002132954141485958, 'mean_word_length': 3.6359143327841843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6600416', 'n_tokens_mistral': 982, 'n_tokens_neox': 941, 'n_words': 254}