feat(export): add --quote flag to control dotenv quote character#291
feat(export): add --quote flag to control dotenv quote character#291Rakesh1002 wants to merge 1 commit into
Conversation
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
|
| 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
| quoteFlag, err := cmd.Flags().GetString("quote") | ||
| if err != nil { | ||
| util.HandleError(err) | ||
| } | ||
|
|
||
| quote, err := quoteCharacter(quoteFlag) | ||
| if err != nil { | ||
| util.HandleError(err) | ||
| } |
There was a problem hiding this comment.
--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!
Description
The
dotenvanddotenv-exportformats hardcode single quotes (KEY='value'). This breaks two common cases reported in Infisical/infisical#1103:\ninside single quotes, so the key isn't parsed as multiline.--env-file: treats the surrounding single quotes as part of the value.Change
Adds a
--quoteflag with valuessingle | double | none(defaultsingle).dotenvanddotenv-exportformats.dotenv-evalis intentionally untouched (it relies on POSIX single-quote semantics for safe shell evaluation).Tests
Added table tests for
quoteCharacter,formatAsDotEnv, andformatAsDotEnvExport, including a multiline-encoded value exported with--quote=double. All existing tests pass.Notes
docs/cli/commands/export.mdx) — happy to open a companion docs PR.Resolves Infisical/infisical#1103