Skip to content

Commit

Permalink
Move command 'spaces:drains:get' to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sbosio committed May 7, 2024
1 parent a124379 commit 3efe17e
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 93 deletions.
30 changes: 30 additions & 0 deletions packages/cli/src/commands/spaces/drains/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'

export default class Get extends Command {
static aliases = ['drains:get']
static topic = 'drains'
static hidden = true
static description = 'display the log drain for a space'
static flags = {
space: flags.string({char: 's', description: 'space for which to get log drain', required: true}),
json: flags.boolean({description: 'output in json format'}),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Get)
const {space, json} = flags
const {body: drain} = await this.heroku.get<Required<Heroku.LogDrain>>(
`/spaces/${space}/log-drain`,
{headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'}},
)

if (json) {
ux.log(JSON.stringify(drain, null, 2))
} else {
ux.log(`${color.cyan(drain.url)} (${color.green(drain.token)})`)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Heroku from '@heroku-cli/schema'

export default class Set extends Command {
static topic = 'drains'
static aliases = ['drains:set']
static hidden = true
static description = 'replaces the log drain for a space'
static flags = {
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {stdout} from 'stdout-stderr'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/spaces/drains/get'
import {expect} from 'chai'
import * as nock from 'nock'

describe('spaces:drains:get', function () {
const drain = {
addon: null,
created_at: '2016-03-23T18:31:50Z',
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
updated_at: '2016-03-23T18:31:50Z',
url: 'https://example.com',
}
let api: nock.Scope

beforeEach(function () {
api = nock('https://api.heroku.com')
.get('/spaces/my-space/log-drain')
.reply(200, drain)
})

afterEach(function () {
api.done()
nock.cleanAll()
})

it('shows the log drain', async function () {
await runCommand(Cmd, [
'--space',
'my-space',
])

expect(stdout.output).to.eq('https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n')
})

it('shows the log drain --json', async function () {
await runCommand(Cmd, [
'--space',
'my-space',
'--json',
])

expect(JSON.parse(stdout.output)).to.eql(drain)
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {expect} from '@oclif/test'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import runCommand from '../../../helpers/runCommand'
import Cmd from '../../../../src/commands/drains/set'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/spaces/drains/set'

describe('drains:set', function () {
describe('spaces:drains:set', function () {
it('shows the log drain', async function () {
const api = nock('https://api.heroku.com:443')
.put('/spaces/my-space/log-drain', {
Expand Down
28 changes: 0 additions & 28 deletions packages/spaces/commands/drains/get.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/spaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports.commands = [
require('./commands/vpn/wait'),
require('./commands/vpn/destroy'),
require('./commands/vpn/update'),
require('./commands/drains/get'),
require('./commands/trusted-ips'),
require('./commands/trusted-ips/remove'),
]
14 changes: 0 additions & 14 deletions packages/spaces/lib/log-drains.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/spaces/test/unit/commands/drains/get.unit.test.js

This file was deleted.

0 comments on commit 3efe17e

Please sign in to comment.