diff --git a/.changeset/hydrogen-env-pull-yes.md b/.changeset/hydrogen-env-pull-yes.md new file mode 100644 index 0000000000..825178d236 --- /dev/null +++ b/.changeset/hydrogen-env-pull-yes.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-hydrogen': patch +--- + +Add a `--yes` confirmation bypass to `hydrogen env pull`. diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index b3c5f7f50b..3ad6e7a463 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -762,6 +762,13 @@ "name": "force", "allowNo": false, "type": "boolean" + }, + "yes": { + "description": "Automatically confirm changes to the local .env file.", + "env": "SHOPIFY_HYDROGEN_FLAG_YES", + "name": "yes", + "allowNo": false, + "type": "boolean" } }, "hasDynamicHelp": false, diff --git a/packages/cli/src/commands/hydrogen/env/pull.test.ts b/packages/cli/src/commands/hydrogen/env/pull.test.ts index 60ce61537e..ecf84c1987 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.test.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.test.ts @@ -282,6 +282,19 @@ describe('pullVariables', () => { }); }); }); + + describe('and --yes is enabled', () => { + it('does not prompt the user to confirm', async () => { + await inTemporaryDirectory(async (tmpDir) => { + const filePath = joinPath(tmpDir, envFile); + await writeFile(filePath, 'EXISTING_TOKEN=1'); + + await runEnvPull({path: tmpDir, yes: true, envFile}); + + expect(renderConfirmationPrompt).not.toHaveBeenCalled(); + }); + }); + }); }); describe('environment variable quoting', () => { diff --git a/packages/cli/src/commands/hydrogen/env/pull.ts b/packages/cli/src/commands/hydrogen/env/pull.ts index e06ed0a4e0..1ad1aed6a3 100644 --- a/packages/cli/src/commands/hydrogen/env/pull.ts +++ b/packages/cli/src/commands/hydrogen/env/pull.ts @@ -1,4 +1,5 @@ import {diffLines} from 'diff'; +import {Flags} from '@oclif/core'; import Command from '@shopify/cli-kit/node/base-command'; import { renderConfirmationPrompt, @@ -73,6 +74,10 @@ export default class EnvPull extends Command { ...commonFlags.envFile, ...commonFlags.path, ...commonFlags.force, + yes: Flags.boolean({ + description: 'Automatically confirm changes to the local .env file.', + env: 'SHOPIFY_HYDROGEN_FLAG_YES', + }), }; async run(): Promise { @@ -87,6 +92,7 @@ interface EnvPullOptions { envFile: string; force?: boolean; path?: string; + yes?: boolean; } export async function runEnvPull({ @@ -95,6 +101,7 @@ export async function runEnvPull({ path: root = process.cwd(), envFile, force, + yes = false, }: EnvPullOptions) { const [{session, config}, cliCommand] = await Promise.all([ login(root), @@ -160,7 +167,7 @@ export async function runEnvPull({ fetchedEnv[key] = isSecret ? `""` : quoteEnvValue(value); }); - if ((await fileExists(dotEnvPath)) && !force) { + if ((await fileExists(dotEnvPath)) && !force && !yes) { const existingEnv = await readFile(dotEnvPath); const patchedEnv = patchEnvFile(existingEnv, fetchedEnv);