mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
af82be19ea
This creates a standard package and interface for defining, querying, setting experiments (`-X` flags). I expect we'll want to continue to introduce various features behind experimental flags. I want to make doing this as easy as possible and I want to make _removing_ experiments as easy as possible as well. The goal with this packge has been to rely on the compiler enforcing our experiment references as much as possible. This means that every experiment is a global variable that must be referenced directly, so when it is removed you'll get compiler errors where the experiment is referenced. This also unifies and makes it easy to grab CLI flags to enable/disable experiments as well as env vars! This way defining an experiment is just a couple lines of code (documented on the package).
35 lines
882 B
Go
35 lines
882 B
Go
package experiment
|
|
|
|
// ID represents an experimental feature.
|
|
//
|
|
// The global vars defined on this package should be used as ID values.
|
|
// This interface is purposely not implement-able outside of this package
|
|
// so that we can rely on the Go compiler to enforce all experiment references.
|
|
type ID interface {
|
|
Env() string
|
|
Flag() string
|
|
Default() bool
|
|
|
|
unexported() // So the ID can't be implemented externally.
|
|
}
|
|
|
|
// basicID implements ID.
|
|
type basicID struct {
|
|
EnvValue string
|
|
FlagValue string
|
|
DefaultValue bool
|
|
}
|
|
|
|
func newBasicID(flag, env string, def bool) ID {
|
|
return &basicID{
|
|
EnvValue: env,
|
|
FlagValue: flag,
|
|
DefaultValue: def,
|
|
}
|
|
}
|
|
|
|
func (id *basicID) Env() string { return id.EnvValue }
|
|
func (id *basicID) Flag() string { return id.FlagValue }
|
|
func (id *basicID) Default() bool { return id.DefaultValue }
|
|
func (id *basicID) unexported() {}
|