@@ -47,9 +47,10 @@ import {
47
47
import { printSecurityDiff , printStackDiff , RequireApproval } from '../diff' ;
48
48
import { ResourceImporter , removeNonImportResources } from '../import' ;
49
49
import { listStacks } from '../list-stacks' ;
50
- import { data , debug , error , highlight , info , success , warning , withCorkedLogging } from '../logging' ;
50
+ import { data , debug , error , highlight , info , success , warning } from '../logging' ;
51
51
import { ResourceMigrator } from '../migrator' ;
52
52
import { deserializeStructure , obscureTemplate , serializeStructure } from '../serialize' ;
53
+ import { CliIoHost } from '../toolkit/cli-io-host' ;
53
54
import { ToolkitError } from '../toolkit/error' ;
54
55
import { numberFromBool , partition } from '../util' ;
55
56
import { formatErrorMessage } from '../util/error' ;
@@ -79,6 +80,11 @@ export interface CdkToolkitProps {
79
80
*/
80
81
deployments : Deployments ;
81
82
83
+ /**
84
+ * The CliIoHost that's used for I/O operations
85
+ */
86
+ ioHost ?: CliIoHost ;
87
+
82
88
/**
83
89
* Whether to be verbose
84
90
*
@@ -136,7 +142,11 @@ export enum AssetBuildTime {
136
142
* deploys applies them to `cloudFormation`.
137
143
*/
138
144
export class CdkToolkit {
139
- constructor ( private readonly props : CdkToolkitProps ) { }
145
+ private ioHost : CliIoHost ;
146
+
147
+ constructor ( private readonly props : CdkToolkitProps ) {
148
+ this . ioHost = props . ioHost ?? CliIoHost . instance ( ) ;
149
+ }
140
150
141
151
public async metadata ( stackName : string , json : boolean ) {
142
152
const stacks = await this . selectSingleStackByName ( stackName ) ;
@@ -371,6 +381,7 @@ export class CdkToolkit {
371
381
const currentTemplate = await this . props . deployments . readCurrentTemplate ( stack ) ;
372
382
if ( printSecurityDiff ( currentTemplate , stack , requireApproval ) ) {
373
383
await askUserConfirmation (
384
+ this . ioHost ,
374
385
concurrency ,
375
386
'"--require-approval" is enabled and stack includes security-sensitive updates' ,
376
387
'Do you wish to deploy these changes' ,
@@ -451,6 +462,7 @@ export class CdkToolkit {
451
462
warning ( `${ motivation } . Rolling back first (--force).` ) ;
452
463
} else {
453
464
await askUserConfirmation (
465
+ this . ioHost ,
454
466
concurrency ,
455
467
motivation ,
456
468
`${ motivation } . Roll back first and then proceed with deployment` ,
@@ -476,6 +488,7 @@ export class CdkToolkit {
476
488
warning ( `${ motivation } . Proceeding with regular deployment (--force).` ) ;
477
489
} else {
478
490
await askUserConfirmation (
491
+ this . ioHost ,
479
492
concurrency ,
480
493
motivation ,
481
494
`${ motivation } . Perform a regular deployment` ,
@@ -1818,11 +1831,12 @@ function buildParameterMap(
1818
1831
* cannot be interactively obtained from a human at the keyboard.
1819
1832
*/
1820
1833
async function askUserConfirmation (
1834
+ ioHost : CliIoHost ,
1821
1835
concurrency : number ,
1822
1836
motivation : string ,
1823
1837
question : string ,
1824
1838
) {
1825
- await withCorkedLogging ( async ( ) => {
1839
+ await ioHost . withCorkedLogging ( async ( ) => {
1826
1840
// only talk to user if STDIN is a terminal (otherwise, fail)
1827
1841
if ( ! TESTING && ! process . stdin . isTTY ) {
1828
1842
throw new ToolkitError ( `${ motivation } , but terminal (TTY) is not attached so we are unable to get a confirmation from the user` ) ;
0 commit comments