forked from toolshed/abra
28
pkg/runtime/config.go
Normal file
28
pkg/runtime/config.go
Normal file
@ -0,0 +1,28 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
type Config struct {
|
||||
Offline bool
|
||||
}
|
||||
|
||||
type Option func(c *Config)
|
||||
|
||||
func New(opts ...Option) *Config {
|
||||
conf := &Config{Offline: false}
|
||||
|
||||
for _, optFunc := range opts {
|
||||
optFunc(conf)
|
||||
}
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
func WithOffline(offline bool) Option {
|
||||
return func(c *Config) {
|
||||
if offline {
|
||||
logrus.Debugf("runtime config: attempting to run in offline mode")
|
||||
}
|
||||
c.Offline = offline
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
// Config is an internal configuration modifier. It can be instantiated on a
|
||||
// command call and can be changed on the fly to help make decisions further
|
||||
// down in the internals, e.g. whether or not to clone the recipe locally or
|
||||
// not.
|
||||
type Config struct {
|
||||
EnsureRecipeExists bool // ensure that the recipe is cloned locally
|
||||
EnsureRecipeLatest bool // ensure the local recipe has latest changes
|
||||
}
|
||||
|
||||
// Option modifies a Config. The convention for passing an Option to a function
|
||||
// is so far, only used in internal/validate.go. A Config is then constructed
|
||||
// and passed down further into the code. This may change in the future but
|
||||
// this is at least the abstraction so far.
|
||||
type Option func(c *Config)
|
||||
|
||||
// New instantiates a Config.
|
||||
func New(opts ...Option) *Config {
|
||||
conf := &Config{
|
||||
EnsureRecipeExists: true,
|
||||
EnsureRecipeLatest: true,
|
||||
}
|
||||
|
||||
for _, optFunc := range opts {
|
||||
optFunc(conf)
|
||||
}
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
// WithEnsureRecipeExists determines whether or not we should be cloning the
|
||||
// local recipe or not. This can be useful for being more adaptable to offline
|
||||
// scenarios.
|
||||
func WithEnsureRecipeExists(ensureRecipeExists bool) Option {
|
||||
return func(c *Config) {
|
||||
if ensureRecipeExists {
|
||||
logrus.Debugf("runtime config: EnsureRecipeExists = %v, ensuring recipes are cloned", ensureRecipeExists)
|
||||
} else {
|
||||
logrus.Debugf("runtime config: EnsureRecipeExists = %v, not cloning recipes", ensureRecipeExists)
|
||||
}
|
||||
|
||||
c.EnsureRecipeExists = ensureRecipeExists
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnsureRecipeLatest determines whether we should update the local recipes
|
||||
// remotely via Git. This can be useful when e.g. ensuring we have the latest
|
||||
// changes before making new ones.
|
||||
func WithEnsureRecipeLatest(ensureRecipeLatest bool) Option {
|
||||
return func(c *Config) {
|
||||
if ensureRecipeLatest {
|
||||
logrus.Debugf("runtime config: EnsureRecipeLatest = %v, ensuring recipes have latest changes", ensureRecipeLatest)
|
||||
} else {
|
||||
logrus.Debugf("runtime config: EnsureRecipeLatest = %v, leaving recipes alone", ensureRecipeLatest)
|
||||
}
|
||||
|
||||
c.EnsureRecipeLatest = ensureRecipeLatest
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user