Skip to content

feat(export): add --quote flag to control dotenv quote character#291

Open
Rakesh1002 wants to merge 1 commit into
Infisical:mainfrom
Rakesh1002:feat/export-quote-character
Open

feat(export): add --quote flag to control dotenv quote character#291
Rakesh1002 wants to merge 1 commit into
Infisical:mainfrom
Rakesh1002:feat/export-quote-character

Conversation

@Rakesh1002

Copy link
Copy Markdown

Description

The dotenv and dotenv-export formats hardcode single quotes (KEY='value'). This breaks two common cases reported in Infisical/infisical#1103:

  • Multiline values (e.g. a Google reCAPTCHA / PEM private key): dotenv loaders do not expand \n inside single quotes, so the key isn't parsed as multiline.
  • Docker --env-file: treats the surrounding single quotes as part of the value.

Change

Adds a --quote flag with values single | double | none (default single).

  • Applies to the dotenv and dotenv-export formats.
  • dotenv-eval is intentionally untouched (it relies on POSIX single-quote semantics for safe shell evaluation).
  • Default preserves current output exactly — fully backward compatible.
infisical export --quote=double      # KEY="value"  (multiline-friendly)
infisical export --quote=none        # KEY=value     (docker --env-file)

Tests

Added table tests for quoteCharacter, formatAsDotEnv, and formatAsDotEnvExport, including a multiline-encoded value exported with --quote=double. All existing tests pass.

Notes

  • Escaping of the chosen quote character inside a value is unchanged from prior behavior (out of scope here; happy to follow up).
  • CLI docs live in the main repo (docs/cli/commands/export.mdx) — happy to open a companion docs PR.

Resolves Infisical/infisical#1103

The dotenv and dotenv-export formats hardcoded single quotes, which breaks
two common cases: multiline values (e.g. a PEM private key) are not parsed as
multiline by dotenv loaders inside single quotes, and Docker's --env-file
treats the surrounding single quotes as part of the value.

Add a --quote flag (single|double|none) that controls the wrapping character
for the dotenv and dotenv-export formats. Defaults to single, so existing
exports are unchanged. dotenv-eval is intentionally left alone since it relies
on POSIX single-quote semantics for safe shell evaluation.

Closes Infisical/infisical#1103
@greptile-apps

greptile-apps Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a --quote flag to the export command that lets users choose single, double, or none as the wrapping character for values in dotenv and dotenv-export output, addressing issues with Docker --env-file and multiline PEM values.

  • quoteCharacter() maps the flag string to the actual delimiter character and is threaded through formatEnvsformatAsDotEnv / formatAsDotEnvExport; dotenv-eval is intentionally left unchanged.
  • New table-driven tests cover all three quote modes, the empty-string default, case-insensitivity, invalid input, and a multiline-encoded value — backward compatibility with the existing single-quote default is explicitly verified.

Confidence Score: 4/5

The change is narrow and backward-compatible; default behavior is unchanged and the new code path is well-tested.

The implementation is clean and the default (single) preserves existing output exactly. The only notable gap is that the --quote flag is parsed and validated before the format is consulted, so it is silently ignored — or raises a confusing error for an invalid value — when non-dotenv formats are used. This is a quality-of-life issue rather than a functional regression.

packages/cmd/export.go — the quoteFlag resolution happens unconditionally before format-specific dispatch.

Important Files Changed

Filename Overview
packages/cmd/export.go Adds --quote flag (single/double/none) for dotenv/dotenv-export formats; quote is always parsed and validated even when format is json/csv/yaml/dotenv-eval, where it has no effect and is silently ignored.
packages/cmd/export_test.go Adds table-driven tests for quoteCharacter, formatAsDotEnv, and formatAsDotEnvExport; coverage is thorough including the default, case-insensitivity, error, and multiline-value cases.

Reviews (1): Last reviewed commit: "feat(export): add --quote flag to contro..." | Re-trigger Greptile

Comment thread packages/cmd/export.go
Comment on lines +77 to +85
quoteFlag, err := cmd.Flags().GetString("quote")
if err != nil {
util.HandleError(err)
}

quote, err := quoteCharacter(quoteFlag)
if err != nil {
util.HandleError(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 --quote silently ignored for non-dotenv formats

quoteCharacter is resolved unconditionally before the format is known, so passing --quote=double --format=json (or yaml, csv, dotenv-eval) produces no output change and no warning. A user who sets this flag expecting it to apply may be left wondering why output is unchanged. Additionally, an invalid quote value (e.g. --quote=backtick --format=json) raises an error even though the flag has no effect on json/csv/yaml/dotenv-eval output — the error message is misleading in that context. Moving the quoteCharacter call inside formatEnvs (or gating it after format validation) would prevent both surprises.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possibility to export env-s with different quota character

1 participant