Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/hydrogen-env-pull-yes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Add a `--yes` confirmation bypass to `hydrogen env pull`.
7 changes: 7 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions packages/cli/src/commands/hydrogen/env/pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/commands/hydrogen/env/pull.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {diffLines} from 'diff';
import {Flags} from '@oclif/core';
import Command from '@shopify/cli-kit/node/base-command';
import {
renderConfirmationPrompt,
Expand Down Expand Up @@ -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<void> {
Expand All @@ -87,6 +92,7 @@ interface EnvPullOptions {
envFile: string;
force?: boolean;
path?: string;
yes?: boolean;
}

export async function runEnvPull({
Expand All @@ -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),
Expand Down Expand Up @@ -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);

Expand Down
Loading