Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amplify-cli): remove redundant prompt #6535 #7098

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } from 'amplify-e2e-cor
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 All @@ -29,8 +27,6 @@ export function addEnvironment(cwd: string, settings: { envName: string; numLaye
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 @@ -150,8 +146,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