Skip to content

Commit 7e96152

Browse files
authored
fix: address UI issues with confirmation prompts on multiple commands (W-21649376) (#3602)
Fixing UI issue with confirmation prompt
1 parent a6e2188 commit 7e96152

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/commands/addons/attach.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {color} from '@heroku/heroku-cli-util'
21
import {Command, flags} from '@heroku-cli/command'
32
import * as Heroku from '@heroku-cli/schema'
3+
import {color} from '@heroku/heroku-cli-util'
44
import {Args, ux} from '@oclif/core'
55

66
import {trapConfirmationRequired} from '../../lib/addons/util.js'
@@ -36,10 +36,16 @@ export default class Attach extends Command {
3636
addon: {name: addon.name}, app: {name: app}, confirm: confirmed, name: as, namespace,
3737
}
3838

39-
ux.action.start(`Attaching ${credential ? color.name(credential) + ' of ' : ''}${color.datastore(addon.name || '')}${as ? ' as ' + color.attachment(as) : ''} to ${color.app(app)}`)
40-
const {body: attachments} = await this.heroku.post<Heroku.AddOnAttachment>('/addon-attachments', {body})
41-
ux.action.stop()
42-
return attachments
39+
try {
40+
ux.action.start(`Attaching ${credential ? color.name(credential) + ' of ' : ''}${color.datastore(addon.name || '')}${as ? ' as ' + color.attachment(as) : ''} to ${color.app(app)}`)
41+
const {body: attachment} = await this.heroku.post<Heroku.AddOnAttachment>('/addon-attachments', {body})
42+
ux.action.stop()
43+
44+
return attachment
45+
} catch (error: unknown) {
46+
ux.action.stop(color.red('!'))
47+
throw error
48+
}
4349
}
4450

4551
if (credential && credential !== 'default') {

src/lib/addons/create_addon.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {color, utils} from '@heroku/heroku-cli-util'
21
import {APIClient} from '@heroku-cli/command'
32
import * as Heroku from '@heroku-cli/schema'
3+
import {color, utils} from '@heroku/heroku-cli-util'
44
import {ux} from '@oclif/core'
55

66
import {waitForAddonProvisioning} from './addons_wait.js'
@@ -40,18 +40,22 @@ export default async function (
4040
plan: {name: plan},
4141
}
4242

43-
ux.action.start(options.actionStartMessage || `Creating ${plan} on ${color.app(app)}`)
44-
const {body: addon} = await heroku.post<Heroku.AddOn>(`/apps/${app}/addons`, {
45-
body,
46-
headers: {
47-
'accept-expansion': 'plan',
48-
'x-heroku-legacy-provider-messages': 'true',
49-
},
50-
})
43+
try {
44+
ux.action.start(options.actionStartMessage || `Creating ${plan} on ${color.app(app)}`)
45+
const {body: addon} = await heroku.post<Heroku.AddOn>(`/apps/${app}/addons`, {
46+
body,
47+
headers: {
48+
'accept-expansion': 'plan',
49+
'x-heroku-legacy-provider-messages': 'true',
50+
},
51+
})
52+
ux.action.stop(options.actionStopMessage || color.green(util.formatPriceText(addon.plan?.price || '')))
5153

52-
ux.action.stop(options.actionStopMessage || color.green(util.formatPriceText(addon.plan?.price || '')))
53-
54-
return addon
54+
return addon
55+
} catch (error: unknown) {
56+
ux.action.stop(color.red('!'))
57+
throw error
58+
}
5559
}
5660

5761
let addon = await util.trapConfirmationRequired<Heroku.AddOn>(app, confirm, confirm => (createAddonRequest(confirm)))

0 commit comments

Comments
 (0)