-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(toolkit): default IoHost supports prompting (#33177)
### Reason for this change The `ClioIoHost` didn't implement `requestResponse` properly, it just returned the default value. However since this implementation is supposed to be exactly what the CLI does, we need to implement prompting. ### Description of changes Implements user prompting. This is not currently used yet by the CLI itself, we will enable this in follow-up ticket. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Added test cases. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
3 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Sends a response to a prompt to stdin | ||
* When using this in tests, call just before the prompt runs. | ||
* | ||
* @example | ||
* ```ts | ||
* sendResponse('y'); | ||
* await prompt('Confirm (y/n)?'); | ||
* ``` | ||
*/ | ||
export function sendResponse(res: string, delay = 0) { | ||
if (!delay) { | ||
setImmediate(() => process.stdin.emit('data', `${res}\n`)); | ||
} else { | ||
setTimeout(() => process.stdin.emit('data', `${res}\n`), delay); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters