Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(spaces): Move command spaces:rename to oclif #2833

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/cli/src/commands/spaces/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import heredoc from 'tsheredoc'

export default class Rename extends Command {
static topic = 'spaces';
static description = 'renames a space';
static example = heredoc(`
$ heroku spaces:rename --from old-space-name --to new-space-name
Renaming space old-space-name to new-space-name... done
`)

static flags = {
from: flags.string({required: true, description: 'current name of space'}),
to: flags.string({required: true, description: 'desired name of space'}),
};

public async run(): Promise<void> {
const {flags} = await this.parse(Rename)
const {to, from} = flags
ux.action.start(`Renaming space from ${color.cyan(from)} to ${color.green(to)}`)
await this.heroku.patch(`/spaces/${from}`, {body: {name: to}})
ux.action.stop()
}
}
25 changes: 25 additions & 0 deletions packages/cli/test/unit/commands/spaces/rename.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {stderr} from 'stdout-stderr'
import Cmd from '../../../../src/commands/spaces/rename'
import runCommand from '../../../helpers/runCommand'
import * as nock from 'nock'
import heredoc from 'tsheredoc'
import expectOutput from '../../../helpers/utils/expectOutput'

describe('spaces:rename', function () {
it('renames a space', async function () {
nock('https://api.heroku.com')
.patch('/spaces/old-space-name', {name: 'new-space-name'})
.reply(200)

await runCommand(Cmd, [
'--from',
'old-space-name',
'--to',
'new-space-name',
])
expectOutput(stderr.output, heredoc(`
Renaming space from old-space-name to new-space-name...
Renaming space from old-space-name to new-space-name... done
`))
})
})
32 changes: 0 additions & 32 deletions packages/spaces/commands/rename.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 @@ -6,7 +6,6 @@ exports.topics = [
]

exports.commands = [
require('./commands/rename'),
require('./commands/wait'),
require('./commands/peering/info'),
require('./commands/peering/index'),
Expand Down
18 changes: 0 additions & 18 deletions packages/spaces/test/unit/commands/rename.unit.test.js

This file was deleted.

Loading