Skip to content

Commit 3b959d2

Browse files
committed
feat(spaces): migrate drains:{set,get} to spaces topic
This commit partially migrates the `drains:set` and `drains:get` commands for `spaces` under the `spaces` topic, so they can be accessed from `spaces:drains:set` and `spaces:drains:get`. The rationale here is that these are `spaces`-specific commands, and there is significant semantic overlap between `drains:add` and `drains:set`. This makes it clearer that these commands are `spaces`-specific. In order to not break comaptibility with existing workflows, the old `drains:{set,get}` commands will continue to work, but remain hidden.
1 parent 0d7e5ca commit 3b959d2

File tree

5 files changed

+72
-63
lines changed

5 files changed

+72
-63
lines changed

packages/spaces/commands/drains/get.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ async function run(context, heroku) {
1313
}
1414
}
1515

16-
module.exports = {
17-
topic: 'drains',
18-
command: 'get',
19-
hidden: true,
16+
const cmd = {
2017
description: 'display the log drain for a space',
2118
needsApp: false,
2219
needsAuth: true,
2320
flags: [
24-
{name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true},
25-
{name: 'json', description: 'output in json format'},
21+
{ name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true },
22+
{ name: 'json', description: 'output in json format' },
2623
],
2724
run: cli.command(run),
2825
}
26+
27+
module.exports = [
28+
Object.assign({topic: 'spaces', command: 'drains:get', hidden: false}, cmd),
29+
Object.assign({topic: 'drains', command: 'get', hidden: true}, cmd)
30+
]

packages/spaces/commands/drains/set.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ async function run(context, heroku) {
1010
cli.warn('It may take a few moments for the changes to take effect.')
1111
}
1212

13-
module.exports = {
14-
topic: 'drains',
15-
command: 'set',
16-
hidden: true,
13+
const cmd = {
1714
description: 'replaces the log drain for a space',
1815
needsApp: false,
1916
needsAuth: true,
@@ -25,3 +22,8 @@ module.exports = {
2522
],
2623
run: cli.command(run),
2724
}
25+
26+
module.exports = [
27+
Object.assign({topic: 'spaces', command: 'drains:set', hidden: false}, cmd),
28+
Object.assign({topic: 'drains', command: 'set', hidden: true}, cmd)
29+
]

packages/spaces/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict'
22

3+
const _ = require('lodash')
4+
35
exports.topics = [
46
{name: 'spaces', description: 'manage heroku private spaces'},
57
{name: 'trusted-ips', hidden: true},
68
]
79

8-
exports.commands = [
10+
exports.commands = _.flatten([
911
require('./commands'),
1012
require('./commands/create'),
1113
require('./commands/destroy'),
@@ -35,4 +37,4 @@ exports.commands = [
3537
require('./commands/outbound-rules/add'),
3638
require('./commands/outbound-rules/remove'),
3739
require('./commands/hosts'),
38-
]
40+
])

packages/spaces/test/unit/commands/drains/get.unit.test.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,48 @@
22
/* globals beforeEach */
33

44
let nock = require('nock')
5-
let cmd = require('../../../../commands/drains/get')
5+
let cmds = require('../../../../commands/drains/get')
66
let expect = require('chai').expect
77
let cli = require('heroku-cli-util')
88

9-
describe('drains:get', function () {
10-
beforeEach(() => cli.mockConsole())
9+
cmds.forEach(cmd => {
10+
describe(`${cmd.topic}:${cmd.command}`, function () {
11+
beforeEach(() => cli.mockConsole())
1112

12-
it('shows the log drain', function () {
13-
let api = nock('https://api.heroku.com:443')
14-
.get('/spaces/my-space/log-drain')
15-
.reply(200, {
13+
it('shows the log drain', function () {
14+
let api = nock('https://api.heroku.com:443')
15+
.get('/spaces/my-space/log-drain')
16+
.reply(200, {
17+
addon: null,
18+
created_at: '2016-03-23T18:31:50Z',
19+
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
20+
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
21+
updated_at: '2016-03-23T18:31:50Z',
22+
url: 'https://example.com',
23+
})
24+
return cmd.run({flags: {space: 'my-space'}})
25+
.then(() => expect(cli.stdout).to.equal(
26+
`https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n`,
27+
)).then(() => api.done())
28+
})
29+
30+
it('shows the log drain --json', function () {
31+
let drain = {
1632
addon: null,
1733
created_at: '2016-03-23T18:31:50Z',
1834
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
1935
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
2036
updated_at: '2016-03-23T18:31:50Z',
2137
url: 'https://example.com',
22-
})
23-
return cmd.run({flags: {space: 'my-space'}})
24-
.then(() => expect(cli.stdout).to.equal(
25-
`https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)
26-
`,
27-
)).then(() => api.done())
28-
})
38+
}
2939

30-
it('shows the log drain --json', function () {
31-
let drain = {
32-
addon: null,
33-
created_at: '2016-03-23T18:31:50Z',
34-
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
35-
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
36-
updated_at: '2016-03-23T18:31:50Z',
37-
url: 'https://example.com',
38-
}
39-
40-
let api = nock('https://api.heroku.com:443')
41-
.get('/spaces/my-space/log-drain')
42-
.reply(200, drain)
43-
return cmd.run({flags: {space: 'my-space', json: true}})
44-
.then(() => expect(JSON.parse(cli.stdout)).to.eql(drain))
45-
.then(() => api.done())
40+
let api = nock('https://api.heroku.com:443')
41+
.get('/spaces/my-space/log-drain')
42+
.reply(200, drain)
43+
return cmd.run({flags: {space: 'my-space', json: true}})
44+
.then(() => expect(JSON.parse(cli.stdout)).to.eql(drain))
45+
.then(() => api.done())
46+
})
4647
})
4748
})
49+

packages/spaces/test/unit/commands/drains/set.unit.test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22
/* globals beforeEach */
33

44
let nock = require('nock')
5-
let cmd = require('../../../../commands/drains/set')
5+
let cmds = require('../../../../commands/drains/set')
66
let expect = require('chai').expect
77
let cli = require('heroku-cli-util')
88

9-
describe('drains:set', function () {
10-
beforeEach(() => cli.mockConsole())
9+
cmds.forEach(cmd => {
10+
describe(`${cmd.topic}:${cmd.command}`, function () {
11+
beforeEach(() => cli.mockConsole())
1112

12-
it('shows the log drain', function () {
13-
let api = nock('https://api.heroku.com:443')
14-
.put('/spaces/my-space/log-drain', {
15-
url: 'https://example.com',
16-
})
17-
.reply(200, {
18-
addon: null,
19-
created_at: '2016-03-23T18:31:50Z',
20-
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
21-
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
22-
updated_at: '2016-03-23T18:31:50Z',
23-
url: 'https://example.com',
24-
})
25-
return cmd.run({args: {url: 'https://example.com'}, flags: {space: 'my-space'}})
26-
.then(() => expect(cli.stdout).to.equal(
27-
`Successfully set drain https://example.com for my-space.
28-
`,
29-
)).then(() => api.done())
13+
it('shows the log drain', function () {
14+
let api = nock('https://api.heroku.com:443')
15+
.put('/spaces/my-space/log-drain', {
16+
url: 'https://example.com',
17+
})
18+
.reply(200, {
19+
addon: null,
20+
created_at: '2016-03-23T18:31:50Z',
21+
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
22+
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
23+
updated_at: '2016-03-23T18:31:50Z',
24+
url: 'https://example.com',
25+
})
26+
return cmd.run({args: {url: 'https://example.com'}, flags: {space: 'my-space'}})
27+
.then(() => expect(cli.stdout).to.equal(
28+
`Successfully set drain https://example.com for my-space.\n`,
29+
)).then(() => api.done())
30+
})
3031
})
3132
})

0 commit comments

Comments
 (0)