Skip to content

Commit c38f0d7

Browse files
committed
add infra uninstall command
1 parent 8f6b439 commit c38f0d7

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vtex/cli-plugin-infra",
33
"description": "vtex plugin infra",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"bugs": "https://github.com/vtex/cli-plugin-infra/issues",
66
"dependencies": {
77
"@oclif/command": "^1",
@@ -57,7 +57,7 @@
5757
],
5858
"topics": {
5959
"infra": {
60-
"description": "Installs, updates, or lists infra services. Run 'vtex infra' to see all 3 subcommands"
60+
"description": "Installs, updates, lists, or uninstalls infra services. Run 'vtex infra' to see all 4 subcommands"
6161
}
6262
}
6363
},

src/commands/infra/uninstall.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { CustomCommand, ColorifyConstants } from 'vtex'
2+
import appsInfraUninstall from '../../modules/uninstall'
3+
4+
export default class InfraUninstall extends CustomCommand {
5+
static description = 'Uninstalls an infra service.'
6+
7+
static examples = [
8+
`${ColorifyConstants.COMMAND_OR_VTEX_REF('vtex infra uninstall')} infra-service`,
9+
]
10+
11+
static flags = { ...CustomCommand.globalFlags }
12+
13+
static args = [
14+
{
15+
name: 'serviceId',
16+
required: true,
17+
description: `Name of the service ${ColorifyConstants.ID(
18+
'({vendor}.{servicename})'
19+
)} to uninstall.`,
20+
},
21+
]
22+
23+
async run() {
24+
const { args } = this.parse(InfraUninstall)
25+
const name = args.serviceId
26+
27+
await appsInfraUninstall(name)
28+
}
29+
}

src/modules/uninstall.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import chalk from 'chalk'
2+
import ora from 'ora'
3+
import { createRouterClient, logger, promptConfirm } from 'vtex'
4+
5+
const router = createRouterClient()
6+
const { uninstallService } = router
7+
8+
const promptUninstall = (service: string) =>
9+
Promise.resolve(promptConfirm(`Are you sure you want to uninstall ${service}?`))
10+
11+
export default async (name: string) => {
12+
const spinner = ora('Uninstalling service').start()
13+
14+
try {
15+
// Confirm the uninstallation
16+
const confirmed = await promptUninstall(name)
17+
if (!confirmed) {
18+
spinner.stop()
19+
logger.info('Uninstallation cancelled')
20+
return
21+
}
22+
23+
spinner.text = 'Uninstalling'
24+
spinner.start()
25+
26+
await uninstallService(name)
27+
28+
spinner.stop()
29+
console.log(`${name} ${chalk.red('uninstalled')}`)
30+
logger.info('Uninstallation complete')
31+
} catch (err) {
32+
spinner.stop()
33+
throw err
34+
}
35+
}

0 commit comments

Comments
 (0)