fix: skip recipe clone / up to date sync for some commands

Continues work of 3dc5662821.
This commit is contained in:
2023-08-01 21:19:20 +02:00
parent 2cd453ae8d
commit 23f5745cb8
7 changed files with 73 additions and 7 deletions

View File

@ -2,14 +2,23 @@ package runtime
import "github.com/sirupsen/logrus"
// Config is a runtime behaviour modifier.
type Config struct {
Offline bool
Offline bool // Whether or not Abra should prefer local / offline access
RecipeExists bool // Whether or not Abra should ensure the recipe is locally cloned
RecipeLatest bool // Whether or not Abra should ensure the recipe has the latest commit
}
// Option is a runtime configuration option.
type Option func(c *Config)
// New creates a new runtime configuration.
func New(opts ...Option) *Config {
conf := &Config{Offline: false}
conf := &Config{
Offline: false,
RecipeExists: true,
RecipeLatest: true,
}
for _, optFunc := range opts {
optFunc(conf)
@ -18,6 +27,8 @@ func New(opts ...Option) *Config {
return conf
}
// WithOffline ensures Abra attempts to prefer local file system and offline
// access.
func WithOffline(offline bool) Option {
return func(c *Config) {
if offline {
@ -26,3 +37,23 @@ func WithOffline(offline bool) Option {
c.Offline = offline
}
}
// WithEnsureRecipeExists ensures recipe exists locally.
func WithEnsureRecipeExists(exists bool) Option {
return func(c *Config) {
if exists {
logrus.Debugf("runtime config: ensuring recipe exists")
}
c.RecipeExists = exists
}
}
// WithEnsureRecipeUpToDate ensures recipe is synced with the remote.
func WithEnsureRecipeUpToDate(upToDate bool) Option {
return func(c *Config) {
if upToDate {
logrus.Debugf("runtime config: ensuring recipe is synced with remote")
}
c.RecipeLatest = upToDate
}
}