Expand description
.env file parser — merged implementation.
Combines the correctness of the original parser (typed errors, key
validation, circular-expansion detection, depth limiting) with the
feature set of the refactored parser (backtick quotes, multiline
values, bare $VAR expansion, inline-comment stripping, configurable
value trimming, and a proper Default impl).
§Format support
| Feature | Supported |
|---|---|
KEY=value | ✓ |
export KEY=value | ✓ |
# comments | ✓ |
Inline # comments | ✓ (opt-in via ParserConfig::allow_inline_comments) |
| Double-quoted values | ✓ |
| Single-quoted values | ✓ |
| Backtick-quoted values | ✓ |
| Multiline values | ✓ (opt-in via ParserConfig::allow_multiline) |
${VAR} expansion | ✓ |
$VAR expansion | ✓ |
| Circular expansion guard | ✓ |
| Strict uppercase keys | ✓ (opt-in via ParserConfig::strict) |
§Compatibility with other modules
Every call site in the codebase uses one of these three patterns:
// Pattern A — most common (all commands)
let parser = Parser::default();
let env_file = parser.parse_file(".env")?;
env_file.vars // HashMap<String, String>
// Pattern B — config override (validate --strict, tests)
let parser = Parser::new(ParserConfig { strict: true, ..Default::default() });
// Pattern C — parse from string (tests, template command)
let vars = parser.parse_content("KEY=value")?;This merged parser satisfies all three patterns without any call-site changes. See § Compatibility notes below for per-module details.
§Error handling
All errors are ParseError variants. Because the commands wrap parser
calls with anyhow::Context (.with_context(|| ...)), the structured
error converts automatically into anyhow::Error at the boundary — no
changes needed in any command file.
§Compatibility notes by module
| Module | Method used | Breaking change? |
|---|---|---|
commands/validate.rs | parse_file(&str) | None — signature preserved |
commands/diff.rs | parse_file(&str) | None |
commands/scan.rs | parse_file(&str) | None |
commands/convert.rs | parse_file(&str) | None |
commands/sync.rs | parse_file(&str) | None |
commands/template.rs | parse_file(&str) | None |
commands/migrate.rs | parse_file(&str) | None |
commands/backup.rs | Not used directly | N/A |
commands/doctor.rs | parse_file(&str) | None |
commands/init.rs | parse_file(&str) | None |
core/converter.rs | EnvFile.vars | None — field name preserved |
| Tests | parse_content | None — method name preserved |
Structs§
- EnvFile
- The result of parsing a
.envfile or string. - Parser
.envfile parser.- Parser
Config - Controls parser behaviour. Construct with
Default::default()and override individual fields as needed.
Enums§
- Parse
Error - Structured parse errors with line numbers and context.
Type Aliases§
- Parse
Result - Convenience alias used throughout the parser internals.