Skip to content

Commit 3e440f5

Browse files
Prompt user for confirmation before deleting Environment.
1 parent 5cec842 commit 3e440f5

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/commands/platform/env/delete.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {ScCommand} from '@dishantlangayan/sc-cli-core'
2+
import {confirm} from '@inquirer/prompts'
23
import {Flags} from '@oclif/core'
34

45
import {resolveOrgConnection} from '../../../lib/org-utils.js'
@@ -14,6 +15,7 @@ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelet
1415
'<%= config.bin %> <%= command.id %> --env-id=MyEnvId',
1516
'<%= config.bin %> <%= command.id %> --org=my-org --name=MyEnvName',
1617
'<%= config.bin %> <%= command.id %> --alias=my-alias --name=MyEnvName',
18+
'<%= config.bin %> <%= command.id %> --env-id=MyEnvId --no-prompt',
1719
]
1820
static override flags = {
1921
alias: Flags.string({
@@ -31,6 +33,10 @@ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelet
3133
description: 'Name of the environment.',
3234
exactlyOne: ['env-id', 'name'],
3335
}),
36+
'no-prompt': Flags.boolean({
37+
default: false,
38+
description: 'Skip confirmation prompt and assume Yes',
39+
}),
3440
org: Flags.string({
3541
char: 'o',
3642
description: 'Organization ID to use. If not specified, uses the default organization or alias if specified.',
@@ -69,6 +75,26 @@ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelet
6975
message = `Multiple environments found with: ${name}. Exactly one environment must match the provided name.`
7076
this.warn(message)
7177
} else {
78+
// Confirm deletion unless --no-prompt flag is set
79+
if (!flags['no-prompt']) {
80+
const envIdentifier = name || envId
81+
try {
82+
const shouldProceed = await confirm({
83+
default: false,
84+
message: `Are you sure you want to delete the environment '${envIdentifier}'?`,
85+
})
86+
87+
if (!shouldProceed) {
88+
this.log('Deletion cancelled.')
89+
this.exit(0)
90+
}
91+
} catch {
92+
// User cancelled the confirmation (Ctrl+C)
93+
this.log('Deletion cancelled.')
94+
this.exit(0)
95+
}
96+
}
97+
7298
// API call to delete environment by id
7399
apiUrl += `/${envIdToDelete}`
74100
await conn.delete<string>(apiUrl)

test/commands/platform/env/delete.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('platform:env:delete', () => {
8080
scConnDeleteStub.returns(deleteSuccessMsg)
8181

8282
// Act
83-
const {stdout} = await runCommand(`platform:env:delete --name ${envName}`)
83+
const {stdout} = await runCommand(`platform:env:delete --name ${envName} --no-prompt`)
8484

8585
// Assert
8686
expect(orgManagerStub.getDefaultOrg.calledOnce).to.be.true
@@ -96,7 +96,7 @@ describe('platform:env:delete', () => {
9696
scConnDeleteStub.returns(deleteSuccessMsg)
9797

9898
// Act
99-
const {stdout} = await runCommand(`platform:env:delete --env-id id${envName}`)
99+
const {stdout} = await runCommand(`platform:env:delete --env-id id${envName} --no-prompt`)
100100

101101
// Assert
102102
expect(scConnDeleteStub.getCall(0).calledWith(`/platform/environments/id${envName}`)).to.be.true
@@ -123,7 +123,7 @@ describe('platform:env:delete', () => {
123123
scConnDeleteStub.returns(deleteSuccessMsg)
124124

125125
// Act
126-
const {stdout} = await runCommand(`platform:env:delete --alias=test-alias --name ${envName}`)
126+
const {stdout} = await runCommand(`platform:env:delete --alias=test-alias --name ${envName} --no-prompt`)
127127

128128
// Assert
129129
expect(orgManagerStub.getOrg.calledWith('test-alias')).to.be.true

0 commit comments

Comments
 (0)