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(container-registry-v5): move container:rm to CLI & upgrade to oclif #2656

Merged
merged 5 commits into from
Feb 27, 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
38 changes: 38 additions & 0 deletions packages/cli/src/commands/container/rm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import color from '@heroku-cli/color'

export default class Rm extends Command {
static topic = 'container'
static description = 'remove the process type from your app'
static usage = '$ heroku container:rm -a APP [-v] PROCESS_TYPE...'
static example = `
${color.cmd('heroku container:rm web')} # Destroys the web container
${color.cmd('heroku container:rm web worker')} # Destroys the web and worker containers`

static strict = false

static flags = {
app: flags.app({required: true}),
}

async run() {
const {argv, flags} = await this.parse(Rm)
const {app} = flags

if (argv.length === 0) {
this.error(`Error: Requires one or more process types\n${Rm.example}`)
}

for (const process of argv as string[]) {
ux.action.start(`Removing container ${process} for ${color.app(app)}`)
await this.heroku.patch(`/apps/${app}/formation/${process}`, {
headers: {
Accept: 'application/vnd.heroku+json; version=3.docker-releases',
},
body: {docker_image: null},
})
ux.action.stop()
}
}
}
54 changes: 54 additions & 0 deletions packages/cli/test/unit/commands/rm.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {stdout, stderr} from 'stdout-stderr'
import Cmd from '../../../src/commands/container/rm'
import runCommand from '../../helpers/runCommand'
import expectOutput from '../../helpers/utils/expectOutput'
import * as nock from 'nock'
import {expect} from 'chai'

describe('container removal', () => {
it('removes one container', async () => {
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.docker-releases'}})
.patch('/apps/testapp/formation/web')
.reply(200, {})
await runCommand(Cmd, [
'--app',
'testapp',
'web',
])
expectOutput(stdout.output, '')
expectOutput(stderr.output, `
Removing container web for ⬢ testapp...
Removing container web for ⬢ testapp... done
`)
})
it('removes two containers', async () => {
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.docker-releases'}})
.patch('/apps/testapp/formation/web')
.reply(200, {})
.patch('/apps/testapp/formation/worker')
.reply(200, {})
await runCommand(Cmd, [
'--app',
'testapp',
'web',
'worker',
])
expectOutput(stdout.output, '')
expectOutput(stderr.output, `
Removing container web for ⬢ testapp...
Removing container web for ⬢ testapp... done
Removing container worker for ⬢ testapp...
Removing container worker for ⬢ testapp... done
`)
})

it('requires a container to be specified', async () => {
await runCommand(Cmd, [
'--app',
'testapp',
]).catch((error: any) => {
expect(error.message).to.contain('Requires one or more process types')
})
expectOutput(stdout.output, '')
})
})
36 changes: 0 additions & 36 deletions packages/container-registry-v5/commands/rm.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/container-registry-v5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
help: pkg.description,
},
commands: [
require('./commands/rm')(pkg.topic),
require('./commands/push')(pkg.topic),
require('./commands/release')(pkg.topic),
require('./commands/run')(pkg.topic),
Expand Down

This file was deleted.

Loading