diff --git a/packages/eas-cli/src/commandUtils/flags.ts b/packages/eas-cli/src/commandUtils/flags.ts index fe6d67c4b8..3a34829b2b 100644 --- a/packages/eas-cli/src/commandUtils/flags.ts +++ b/packages/eas-cli/src/commandUtils/flags.ts @@ -26,15 +26,24 @@ export const EasNonInteractiveAndJsonFlags = { }), }; +const EasEnvironmentFlagParameters = { + description: "Environment variable's environment", + parse: upperCaseAsync, + options: mapToLowercase([ + EnvironmentVariableEnvironment.Development, + EnvironmentVariableEnvironment.Preview, + EnvironmentVariableEnvironment.Production, + ]), +}; + export const EASEnvironmentFlag = { + environment: Flags.enum(EasEnvironmentFlagParameters), +}; + +export const EASMultiEnvironmentFlag = { environment: Flags.enum({ - description: "Environment variable's environment", - parse: upperCaseAsync, - options: mapToLowercase([ - EnvironmentVariableEnvironment.Development, - EnvironmentVariableEnvironment.Preview, - EnvironmentVariableEnvironment.Production, - ]), + ...EasEnvironmentFlagParameters, + multiple: true, }), }; diff --git a/packages/eas-cli/src/commands/env/create.ts b/packages/eas-cli/src/commands/env/create.ts index 22af8b1bdf..e07039a2e6 100644 --- a/packages/eas-cli/src/commands/env/create.ts +++ b/packages/eas-cli/src/commands/env/create.ts @@ -112,7 +112,7 @@ export default class EnvironmentVariableCreate extends EasCommand { } if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const environments = [environment]; diff --git a/packages/eas-cli/src/commands/env/delete.ts b/packages/eas-cli/src/commands/env/delete.ts index 66c388283e..d47935fdc0 100644 --- a/packages/eas-cli/src/commands/env/delete.ts +++ b/packages/eas-cli/src/commands/env/delete.ts @@ -52,7 +52,7 @@ export default class EnvironmentVariableDelete extends EasCommand { if (scope === EnvironmentVariableScope.Project) { if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } } diff --git a/packages/eas-cli/src/commands/env/get.ts b/packages/eas-cli/src/commands/env/get.ts index 6db4dbe747..bcfdfbc19a 100644 --- a/packages/eas-cli/src/commands/env/get.ts +++ b/packages/eas-cli/src/commands/env/get.ts @@ -70,7 +70,7 @@ export default class EnvironmentVariableGet extends EasCommand { } if (!environment && scope === EnvironmentVariableScope.Project) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const variable = await getVariableAsync(graphqlClient, scope, projectId, name, environment); diff --git a/packages/eas-cli/src/commands/env/link.ts b/packages/eas-cli/src/commands/env/link.ts index c325b9552e..c9445d8657 100644 --- a/packages/eas-cli/src/commands/env/link.ts +++ b/packages/eas-cli/src/commands/env/link.ts @@ -61,7 +61,7 @@ export default class EnvironmentVariableLink extends EasCommand { } if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const linkedVariable = await EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync( diff --git a/packages/eas-cli/src/commands/env/list.ts b/packages/eas-cli/src/commands/env/list.ts index 39a0a3bd99..b5fd7875d7 100644 --- a/packages/eas-cli/src/commands/env/list.ts +++ b/packages/eas-cli/src/commands/env/list.ts @@ -50,7 +50,7 @@ export default class EnvironmentValueList extends EasCommand { }); if (scope === EnvironmentVariableScope.Project && !environment) { - environment = await promptVariableEnvironmentAsync(false); + environment = await promptVariableEnvironmentAsync({ nonInteractive: false }); } const variables = await this.getVariablesForScopeAsync(graphqlClient, { diff --git a/packages/eas-cli/src/commands/env/pull.ts b/packages/eas-cli/src/commands/env/pull.ts index 5c88940131..debbcbc3a5 100644 --- a/packages/eas-cli/src/commands/env/pull.ts +++ b/packages/eas-cli/src/commands/env/pull.ts @@ -34,7 +34,7 @@ export default class EnvironmentVariablePull extends EasCommand { } = await this.parse(EnvironmentVariablePull); if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const { privateProjectConfig: { projectId }, diff --git a/packages/eas-cli/src/commands/env/unlink.ts b/packages/eas-cli/src/commands/env/unlink.ts index 85640e5ee2..8176ab69ba 100644 --- a/packages/eas-cli/src/commands/env/unlink.ts +++ b/packages/eas-cli/src/commands/env/unlink.ts @@ -41,7 +41,7 @@ export default class EnvironmentVariableUnlink extends EasCommand { }); if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const projectDisplayName = await getDisplayNameForProjectIdAsync(graphqlClient, projectId); diff --git a/packages/eas-cli/src/commands/env/update.ts b/packages/eas-cli/src/commands/env/update.ts index f345b8bf81..74f46f262a 100644 --- a/packages/eas-cli/src/commands/env/update.ts +++ b/packages/eas-cli/src/commands/env/update.ts @@ -81,7 +81,7 @@ export default class EnvironmentVariableUpdate extends EasCommand { ]); if (!environment) { - environment = await promptVariableEnvironmentAsync(nonInteractive); + environment = await promptVariableEnvironmentAsync({ nonInteractive }); } const environments = environment ? [environment] : undefined; diff --git a/packages/eas-cli/src/utils/prompts.ts b/packages/eas-cli/src/utils/prompts.ts index ee58c42634..30f9bfdff4 100644 --- a/packages/eas-cli/src/utils/prompts.ts +++ b/packages/eas-cli/src/utils/prompts.ts @@ -1,21 +1,53 @@ import chalk from 'chalk'; +import capitalize from './expodash/capitalize'; import { EnvironmentVariableEnvironment } from '../graphql/generated'; import { promptAsync, selectAsync } from '../prompts'; -export async function promptVariableEnvironmentAsync( - nonInteractive: boolean -): Promise { +type EnvironmentPromptArgs = { + nonInteractive: boolean; + selectedEnvironments?: EnvironmentVariableEnvironment[]; +}; + +export function promptVariableEnvironmentAsync( + input: EnvironmentPromptArgs & { multiple: true } +): Promise; +export function promptVariableEnvironmentAsync( + input: EnvironmentPromptArgs & { multiple?: false } +): Promise; + +export async function promptVariableEnvironmentAsync({ + nonInteractive, + selectedEnvironments, + multiple = false, +}: EnvironmentPromptArgs & { multiple?: boolean }): Promise< + EnvironmentVariableEnvironment[] | EnvironmentVariableEnvironment +> { if (nonInteractive) { throw new Error( 'The `--environment` flag must be set when running in `--non-interactive` mode.' ); } - return await selectAsync('Select environment:', [ - { title: 'Development', value: EnvironmentVariableEnvironment.Development }, - { title: 'Preview', value: EnvironmentVariableEnvironment.Preview }, - { title: 'Production', value: EnvironmentVariableEnvironment.Production }, - ]); + if (!multiple) { + return await selectAsync( + 'Select environment:', + Object.values(EnvironmentVariableEnvironment).map(environment => ({ + title: capitalize(environment), + value: environment, + })) + ); + } + const { environments } = await promptAsync({ + message: 'Select environment:', + name: 'environments', + type: 'multiselect', + choices: Object.values(EnvironmentVariableEnvironment).map(environment => ({ + title: capitalize(environment), + value: environment, + selected: selectedEnvironments?.includes(environment), + })), + }); + return environments; } export async function promptVariableValueAsync({ nonInteractive,