feat(config): configure every flag via env var#19
Merged
Conversation
Any command-line flag now also reads from an environment variable derived from its name (PARAKEET_ prefix, upper snake case): --log-level maps to PARAKEET_LOG_LEVEL, --ffmpeg-timeout to PARAKEET_FFMPEG_TIMEOUT, etc. A single applyEnvDefaults helper walks flag.CommandLine after Parse: flags set explicitly on the CLI are left untouched, the rest fall back to their env var via flag.Value.Set so the flag's own type does the parsing. Precedence is CLI flag > env var > default. Invalid env values are ignored with a warning (the previous value is restored, since flag numeric Set clobbers to zero on parse error) so a typo never corrupts the config. New flags get an env var for free, with no extra wiring. Removes the bespoke envOr/envInt helpers that only covered PARAKEET_GPU and PARAKEET_GPU_DEVICE; both keep working through the generic mapping. Adds table tests for the mapping, precedence, typed parsing and invalid values, and rewrites the README env var section around the generic rule.
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.
Every command-line flag is also configurable through an environment variable. Flags and env vars are interchangeable.
The env var name is the flag name uppercased, dashes turned into underscores, prefixed with
PARAKEET_.-portPARAKEET_PORT-log-levelPARAKEET_LOG_LEVEL-ffmpeg-timeoutPARAKEET_FFMPEG_TIMEOUTFeatures
applyEnvDefaultsruns afterflag.Parse()and fills any flag not passed on the CLI from its matching env var, viaflag.Value.Setso the flag's own type parses the value.Fixes
flagzeroes numeric flags even whenSetfails.Tests
gofmt,go vet,go build ./...,go test ./...green.PARAKEET_LOG_FORMAT=jsonproduced JSON logs,PARAKEET_MODELSwas honoured. Port binding was not exercised in the sandbox (no ONNX Runtime); the int path is covered by unit tests.