feat: generate template from .env file#630
Open
amahuli03 wants to merge 4 commits intotheskumar:mainfrom
Open
Conversation
Add core function for generating .env template files from existing .env files. Values are replaced with key names by default. Supports inline directives ::dotenv-template-preserve and ::dotenv-template-exclude. Directives are stripped from output by default, controllable via keep_directives parameter.
Add `dotenv template` subcommand to generate .env template files. Supports optional output path argument and --keep-directives flag. Fix _strip_directives to clean up bare comment markers left after stripping.
Cover core value replacement, directives, keep_directives flag, file path input, and CLI subcommand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
dotenv templateCLI command andgenerate_template()Python API to generate environment template files from existing.envfiles. Closes #618.SECRET_KEY=abc123→SECRET_KEY=SECRET_KEY)exportprefixes are preserved# ::dotenv-template-preserve— keeps the line's value as-is (useful for non-sensitive defaults)# ::dotenv-template-exclude— omits the line from the template--keep-directivesflag retains themUsage
Given a
.envfile:Python API
Test plan
python -m pytest tests/test_main.py tests/test_cli.py -k template -v— 14 tests covering value replacement, directives, keep_directives flag, file output, empty input, and error handling.envwith mixed directives and verify output matches expected template