11import { ScCommand } from '@dishantlangayan/sc-cli-core'
2+ import { confirm } from '@inquirer/prompts'
23import { Flags } from '@oclif/core'
34
45import { 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 )
0 commit comments