Skip to content

Commit 0cf5c26

Browse files
authored
fix: add a required input prompt for use in region input (#2292)
* fix: add a required input prompt for use in region input * PR Updates * api update
1 parent 1f56a5f commit 0cf5c26

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

.changeset/shaggy-pens-sort.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aws-amplify/cli-core': patch
3+
'@aws-amplify/backend-cli': patch
4+
---
5+
6+
add a required input prompt for use in region input

packages/cli-core/API.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import { WriteStream } from 'node:tty';
1313
export class AmplifyPrompter {
1414
static input: (options: {
1515
message: string;
16+
required?: never;
1617
defaultValue?: string;
18+
} | {
19+
message: string;
20+
required: true;
21+
defaultValue?: never;
1722
}) => Promise<string>;
1823
static secretValue: (promptMessage?: string) => Promise<string>;
1924
static yesOrNo: (options: {

packages/cli-core/src/prompter/amplify_prompts.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,32 @@ export class AmplifyPrompter {
4343
* @param options for displaying the prompt
4444
* @param options.message display for the prompt
4545
* @param options.defaultValue if user submits without typing anything. Default: "."
46+
* @param options.required if the user input is required, incompatible with options.defaultValue
4647
* @returns Promise<string> the user input
4748
*/
48-
static input = async (options: {
49-
message: string;
50-
defaultValue?: string;
51-
}): Promise<string> => {
52-
const response = await input({
49+
static input = async (
50+
options:
51+
| {
52+
message: string;
53+
required?: never;
54+
defaultValue?: string;
55+
}
56+
| {
57+
message: string;
58+
required: true;
59+
defaultValue?: never;
60+
}
61+
): Promise<string> => {
62+
if (options.required) {
63+
return input({
64+
message: options.message,
65+
validate: (val: string) =>
66+
val && val.length > 0 ? true : 'Cannot be empty',
67+
});
68+
}
69+
return input({
5370
message: options.message,
5471
default: options.defaultValue ?? '',
5572
});
56-
return response;
5773
};
5874
}

packages/cli/src/commands/configure/configure_profile_command.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void describe('configure command', () => {
4242
emitSuccessMock.mock.resetCalls();
4343
});
4444

45-
void it('configures a profile with an IAM user', async (contextual) => {
45+
void it('fails to configure a profile with a name that already has a profile', async (contextual) => {
4646
const mockProfileExists = mock.method(
4747
profileController,
4848
'profileExists',
@@ -65,7 +65,7 @@ void describe('configure command', () => {
6565
});
6666
});
6767

68-
void it('configures a profile with an IAM user', async (contextual) => {
68+
void it('configures a profile with an existing IAM user credentials', async (contextual) => {
6969
const mockProfileExists = mock.method(
7070
profileController,
7171
'profileExists',
@@ -84,10 +84,10 @@ void describe('configure command', () => {
8484
}
8585
);
8686

87-
const mockInput = contextual.mock.method(
87+
const mockRequiredInput = contextual.mock.method(
8888
AmplifyPrompter,
8989
'input',
90-
(options: { message: string; defaultValue?: string }) => {
90+
(options: { message: string; required: true }) => {
9191
if (options.message.includes('Enter the AWS region to use')) {
9292
return Promise.resolve(testRegion);
9393
}
@@ -105,7 +105,7 @@ void describe('configure command', () => {
105105

106106
assert.equal(mockProfileExists.mock.callCount(), 1);
107107
assert.equal(mockSecretValue.mock.callCount(), 2);
108-
assert.equal(mockInput.mock.callCount(), 1);
108+
assert.equal(mockRequiredInput.mock.callCount(), 1);
109109
assert.equal(mockHasIAMUser.mock.callCount(), 1);
110110
assert.equal(mockAppendAWSFiles.mock.callCount(), 1);
111111
assert.deepStrictEqual(mockAppendAWSFiles.mock.calls[0].arguments[0], {
@@ -121,7 +121,7 @@ void describe('configure command', () => {
121121
});
122122
});
123123

124-
void it('configures a profile without an IAM user', async (contextual) => {
124+
void it('configures a profile without an existing IAM user', async (contextual) => {
125125
const mockProfileExists = mock.method(
126126
profileController,
127127
'profileExists',

packages/cli/src/commands/configure/configure_profile_command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class ConfigureProfileCommand
7373

7474
const region = await AmplifyPrompter.input({
7575
message: `Enter the AWS region to use with the '${profileName}' profile (eg us-east-1, us-west-2, etc):`,
76+
required: true,
7677
});
7778

7879
await this.profileController.createOrAppendAWSFiles({

0 commit comments

Comments
 (0)