Skip to content

feat(config): configure every flag via env var#19

Merged
achetronic merged 1 commit into
masterfrom
feat/flags-from-env
Jul 1, 2026
Merged

feat(config): configure every flag via env var#19
achetronic merged 1 commit into
masterfrom
feat/flags-from-env

Conversation

@achetronic

@achetronic achetronic commented Jul 1, 2026

Copy link
Copy Markdown
Owner

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_.

Flag Env var
-port PARAKEET_PORT
-log-level PARAKEET_LOG_LEVEL
-ffmpeg-timeout PARAKEET_FFMPEG_TIMEOUT

Features

  • applyEnvDefaults runs after flag.Parse() and fills any flag not passed on the CLI from its matching env var, via flag.Value.Set so the flag's own type parses the value.
  • Precedence: CLI flag, then env var, then default.
  • New flags get an env var with no extra wiring.

Fixes

  • Invalid env values are ignored with a warning and the flag keeps its value, since flag zeroes numeric flags even when Set fails.

Tests

  • Table tests for name mapping, precedence, typed parsing (bool, duration) and invalid values.
  • gofmt, go vet, go build ./..., go test ./... green.
  • Live smoke: PARAKEET_LOG_FORMAT=json produced JSON logs, PARAKEET_MODELS was honoured. Port binding was not exercised in the sandbox (no ONNX Runtime); the int path is covered by unit tests.

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.
@achetronic achetronic changed the title feat(config): configure every flag via env var too feat(config): configure every flag via env var Jul 1, 2026
@achetronic achetronic self-assigned this Jul 1, 2026
@achetronic achetronic added the enhancement New feature or request label Jul 1, 2026
@achetronic
achetronic merged commit c8f1954 into master Jul 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant