Skip to content

Commit

Permalink
fix(amplify-cli): remove redundant prompt aws-amplify#6535 (aws-ampli…
Browse files Browse the repository at this point in the history
…fy#7098)

* fix: remove redundant prompt aws-amplify#6535
  • Loading branch information
gitaalekhyapaul authored and akshbhu committed Aug 15, 2021
1 parent b881b0f commit a6e0ff9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 13 additions & 1 deletion packages/amplify-cli/src/init-steps/s0-analyzeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ async function getEnvName(context: $TSContext) {
await newEnvQuestion();
} else {
const allEnvs = context.amplify.getAllEnvs();
const envAddExec = checkEnvAddExec(context);

if (allEnvs.length > 0) {
if (allEnvs.length > 0 && envAddExec === false) {
if (await context.amplify.confirmPrompt('Do you want to use an existing environment?')) {
const envQuestion: inquirer.ListQuestion = {
type: 'list',
Expand All @@ -268,6 +269,8 @@ async function getEnvName(context: $TSContext) {
} else {
await newEnvQuestion();
}
} else if (envAddExec === true && context.parameters.first) {
envName = context.parameters.first;
} else {
await newEnvQuestion();
}
Expand Down Expand Up @@ -310,3 +313,12 @@ function getDefaultEditor() {

return localEnvInfo.defaultEditor;
}

/**
* Checks if `amplify env add` has been executed
* @param {$TSContext} context The Amplify context object
* @returns `boolean`
*/
function checkEnvAddExec(context): boolean {
return context.parameters.command === 'env' && context.parameters.array[0] === 'add';
}
6 changes: 0 additions & 6 deletions packages/amplify-e2e-tests/src/environment/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { nspawn as spawn, getCLIPath, getSocialProviders, isCI } from 'amplify-e
export function addEnvironment(cwd: string, settings: { envName: string; numLayers?: number }): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true })
.wait('Do you want to use an existing environment?')
.sendLine('n')
.wait('Enter a name for the environment')
.sendLine(settings.envName)
.wait('Select the authentication method you want to use:')
Expand Down Expand Up @@ -58,8 +56,6 @@ export function addEnvironmentYes(cwd: string, settings: { envName: string; disa
export function addEnvironmentWithImportedAuth(cwd: string, settings: { envName: string; currentEnvName: string }): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true })
.wait('Do you want to use an existing environment?')
.sendConfirmNo()
.wait('Enter a name for the environment')
.sendLine(settings.envName)
.wait('Select the authentication method you want to use:')
Expand Down Expand Up @@ -179,8 +175,6 @@ export function addEnvironmentHostedUI(cwd: string, settings: { envName: string
} = getSocialProviders();
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['env', 'add'], { cwd, stripColors: true })
.wait('Do you want to use an existing environment?')
.sendLine('n')
.wait('Enter a name for the environment')
.sendLine(settings.envName)
.wait('Select the authentication method you want to use:')
Expand Down

0 comments on commit a6e0ff9

Please sign in to comment.