Skip to content

Commit

Permalink
fix: remove redundant prompt aws-amplify#6535
Browse files Browse the repository at this point in the history
  • Loading branch information
gitaalekhyapaul committed Apr 15, 2021
1 parent f1a99bd commit dfdf4ee
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion packages/amplify-cli/src/init-steps/s0-analyzeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async function getEnvName(context) {
} else {
const allEnvs = context.amplify.getAllEnvs();

if (allEnvs.length > 0) {
if (allEnvs.length > 0 && addNewEnv(context).exec === false) {
if (await context.amplify.confirmPrompt('Do you want to use an existing environment?')) {
const envQuestion: inquirer.ListQuestion = {
type: 'list',
Expand All @@ -255,6 +255,8 @@ async function getEnvName(context) {
} else {
await newEnvQuestion();
}
} else if (addNewEnv(context).exec === true && addNewEnv(context).envName) {
envName = addNewEnv(context).envName;
} else {
await newEnvQuestion();
}
Expand Down Expand Up @@ -297,3 +299,29 @@ function getDefaultEditor() {

return localEnvInfo.defaultEditor;
}

/**
*Checks if `amplify env add` has been executed, and extract environment name if exists
* @param {$TSContext} context The Amplify context object
* @returns `{exec: boolean, envName?: string | null}`
*
* `exec` denotes if `amplify env add` has been executed
*
* `envName` extracts environment name if provided
*/
function addNewEnv(context): { exec: boolean; envName?: string | null } {
if (context.parameters.command === 'env' && context.parameters.array[0] === 'add') {
let envName = null;
if (context.parameters.first) {
envName = context.parameters.first;
}
return {
exec: true,
envName,
};
} else {
return {
exec: false,
};
}
}

0 comments on commit dfdf4ee

Please sign in to comment.