config: add WithExplicitPath for a CLI's own --config flag

A highest-priority, must-exist override layer above the working
directory -- the common "flag always wins, but a typo'd path should
fail loudly" pattern most Yetano CLIs need, generalized here instead
of reimplementing it in each application (first consumer: yet's own
--config flag, see the yet submodule).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Sonnet 5 committed 2026-09-19 16:50:22 +02:00
1 parent 13801bec11
commit 689469eb32
3 files changed
+110 -4

No files matched your search

+12
View File
@@ -67,6 +67,7 @@ type Resolver struct {
envExpansion bool
env paths.Environment
pathsOpts []paths.Option
explicitPath string
}
// Option configures a Resolver constructed by New/For.
@@ -161,6 +162,17 @@ func WithPathsOptions(opts ...paths.Option) Option {
return func(r *Resolver) { r.pathsOpts = append(r.pathsOpts, opts...) }
}
// WithExplicitPath adds path as the highest-priority layer -- above the
// working directory -- for a CLI's own explicit "--config <path>"-style
// flag. Unlike every other (optional) layer, an explicit path that does
// not exist is an error from Resolve/ResolveAll/LoadMerged/Explain,
// rather than being silently skipped: a typo'd --config flag should
// fail loudly, not fall through to a different layer. Passing "" (the
// default) disables this layer entirely.
func WithExplicitPath(path string) Option {
return func(r *Resolver) { r.explicitPath = path }
}
// Application returns the Application this Resolver was built for.
func (r *Resolver) Application() core.Application { return r.app }