Would it be a good idea to add a feature for handling configuration files to [Optique]?
-
Would it be a good idea to add a feature for handling configuration files to Optique? 🤔
-
After deep thinking, I've designed a satisfying solution and broke it down into 4 issues:
-
Annotations system (#83): Low-level primitive that allows passing runtime context to parsers via
parse()options -
SourceContextinterface (#85): High-level system for composing multiple data sources (env, config, etc.) with clear priority ordering viarunWith() -
@optique/config(#84): Configuration file support with Standard Schema validation (Zod, Valibot, etc.) -
@optique/env(#86): Environment variables support with automatic type conversion
The key insight: use a two-pass parsing approach where the first pass extracts the config file path, then the second pass runs with config data injected as annotations. All sources can be composed together with
runWith([envContext, configContext])for automatic priority handling: CLI > environment variables > configuration file > default values. -