From 50f175932a04abc409ad7f86fc3eda0e1bda38ce Mon Sep 17 00:00:00 2001 From: Eric Black Date: Tue, 23 Apr 2024 10:27:00 -0700 Subject: [PATCH] Convert spaces:rename to oclif --- packages/cli/src/commands/spaces/rename.ts | 26 +++++++++++++++ .../unit/commands/spaces/rename.unit.test.ts | 25 +++++++++++++++ packages/spaces/commands/rename.js | 32 ------------------- packages/spaces/index.js | 1 - .../test/unit/commands/rename.unit.test.js | 18 ----------- 5 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 packages/cli/src/commands/spaces/rename.ts create mode 100644 packages/cli/test/unit/commands/spaces/rename.unit.test.ts delete mode 100644 packages/spaces/commands/rename.js delete mode 100644 packages/spaces/test/unit/commands/rename.unit.test.js diff --git a/packages/cli/src/commands/spaces/rename.ts b/packages/cli/src/commands/spaces/rename.ts new file mode 100644 index 0000000000..80cb5fc613 --- /dev/null +++ b/packages/cli/src/commands/spaces/rename.ts @@ -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 { + 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() + } +} diff --git a/packages/cli/test/unit/commands/spaces/rename.unit.test.ts b/packages/cli/test/unit/commands/spaces/rename.unit.test.ts new file mode 100644 index 0000000000..dafc9c0b1c --- /dev/null +++ b/packages/cli/test/unit/commands/spaces/rename.unit.test.ts @@ -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 + `)) + }) +}) diff --git a/packages/spaces/commands/rename.js b/packages/spaces/commands/rename.js deleted file mode 100644 index 14ba819eaa..0000000000 --- a/packages/spaces/commands/rename.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict' - -let cli = require('heroku-cli-util') - -async function run(context, heroku) { - let to = context.flags.to - let from = context.flags.from - let request = heroku.request({ - method: 'PATCH', - path: `/spaces/${from}`, - body: {name: to}, - }) - await cli.action(`Renaming space from ${cli.color.cyan(from)} to ${cli.color.green(to)}`, request) -} - -module.exports = { - topic: 'spaces', - command: 'rename', - description: 'renames a space', - help: `Example: - - $ heroku spaces:rename --from old-space-name --to new-space-name - Renaming space old-space-name to new-space-name... done -`, - needsApp: false, - needsAuth: true, - flags: [ - {name: 'from', hasValue: true, required: true, description: 'current name of space'}, - {name: 'to', hasValue: true, required: true, description: 'desired name of space'}, - ], - run: cli.command(run), -} diff --git a/packages/spaces/index.js b/packages/spaces/index.js index 2847969db8..c77bef9735 100644 --- a/packages/spaces/index.js +++ b/packages/spaces/index.js @@ -6,7 +6,6 @@ exports.topics = [ ] exports.commands = [ - require('./commands/rename'), require('./commands/wait'), require('./commands/peering/info'), require('./commands/peering/index'), diff --git a/packages/spaces/test/unit/commands/rename.unit.test.js b/packages/spaces/test/unit/commands/rename.unit.test.js deleted file mode 100644 index 2a87c1a3aa..0000000000 --- a/packages/spaces/test/unit/commands/rename.unit.test.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' -/* globals beforeEach */ - -let nock = require('nock') -let cmd = require('../../../commands/rename') -let cli = require('heroku-cli-util') - -describe('spaces:rename', function () { - beforeEach(() => cli.mockConsole()) - - it('renames a space', function () { - let api = nock('https://api.heroku.com:443') - .patch('/spaces/old-space-name', {name: 'new-space-name'}) - .reply(200) - return cmd.run({flags: {from: 'old-space-name', to: 'new-space-name'}}) - .then(() => api.done()) - }) -})