feat(cli): add --env and --env-file for local runtime env vars - #440
Open
mercael91 wants to merge 1 commit into
Open
feat(cli): add --env and --env-file for local runtime env vars#440mercael91 wants to merge 1 commit into
mercael91 wants to merge 1 commit into
Conversation
Add two new CLI options to the functions-framework entry point: - --env KEY=VALUE (repeatable): set individual runtime environment variables before the function module is loaded. - --env-file PATH: load runtime environment variables from a .env file. Supports comments (#), blank lines, and quoted values. Values from --env-file are applied first, then any --env flags override them. This allows developers to maintain a base .env file while selectively overriding specific variables for different test scenarios. The .env parser handles: - Comment lines (starting with #) - Blank lines - Double-quoted and single-quoted values - Values with leading/trailing whitespace (trimmed) Fixes GoogleCloudPlatform#215 Signed-off-by: mercael91 <mercael91@users.noreply.github.com>
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 two new CLI options to the functions-framework entry point for passing runtime environment variables during local testing.
Changes
--env KEY=VALUE(repeatable): Set individual runtime environment variables before the function module is loaded.--env-file PATH: Load runtime environment variables from a.envfile. Supports comments (#), blank lines, and quoted values.Behavior
--env-fileare applied first, then any--envflags override them..envfile while selectively overriding specific variables for different test scenarios..env file support
#)Usage examples
Tests
6 new tests covering:
--envsets environment variables--env-fileloads from file (with comments, quotes, whitespace)--envoverrides--env-filevalues--envformat error--env-fileerror--env-fileline format errorAll 18 tests pass.
Fixes #215
CLA: signed