forked from toolshed/abra
		
	fix: skip recipe clone / up to date sync for some commands
Continues work of 3dc5662821.
			
			
This commit is contained in:
		@ -84,7 +84,11 @@ var appLogsCommand = cli.Command{
 | 
			
		||||
	Before:       internal.SubCommandBefore,
 | 
			
		||||
	BashComplete: autocomplete.AppNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		conf := runtime.New(runtime.WithOffline(internal.Offline))
 | 
			
		||||
		conf := runtime.New(
 | 
			
		||||
			runtime.WithOffline(internal.Offline),
 | 
			
		||||
			runtime.WithEnsureRecipeExists(false),
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		app := internal.ValidateApp(c, conf)
 | 
			
		||||
 | 
			
		||||
		cl, err := client.New(app.Server)
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,11 @@ var appNewCommand = cli.Command{
 | 
			
		||||
	Before:    internal.SubCommandBefore,
 | 
			
		||||
	ArgsUsage: "[<recipe>]",
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		conf := runtime.New(runtime.WithOffline(internal.Offline))
 | 
			
		||||
		conf := runtime.New(
 | 
			
		||||
			runtime.WithOffline(internal.Offline),
 | 
			
		||||
			runtime.WithEnsureRecipeUpToDate(false),
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		recipe := internal.ValidateRecipeWithPrompt(c, conf)
 | 
			
		||||
 | 
			
		||||
		if err := recipePkg.EnsureUpToDate(recipe.Name, conf); err != nil {
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,11 @@ your SSH keys configured on your account.
 | 
			
		||||
	Before:       internal.SubCommandBefore,
 | 
			
		||||
	BashComplete: autocomplete.RecipeNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		conf := runtime.New(runtime.WithOffline(internal.Offline))
 | 
			
		||||
		conf := runtime.New(
 | 
			
		||||
			runtime.WithOffline(internal.Offline),
 | 
			
		||||
			runtime.WithEnsureRecipeUpToDate(false),
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		recipe := internal.ValidateRecipeWithPrompt(c, conf)
 | 
			
		||||
 | 
			
		||||
		imagesTmp, err := getImageVersions(recipe)
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,11 @@ auto-generate it for you. The <recipe> configuration will be updated on the
 | 
			
		||||
local file system.
 | 
			
		||||
`,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		conf := runtime.New(runtime.WithOffline(internal.Offline))
 | 
			
		||||
		conf := runtime.New(
 | 
			
		||||
			runtime.WithOffline(internal.Offline),
 | 
			
		||||
			runtime.WithEnsureRecipeUpToDate(false),
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		recipe := internal.ValidateRecipeWithPrompt(c, conf)
 | 
			
		||||
 | 
			
		||||
		mainApp, err := internal.GetMainAppImage(recipe)
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,11 @@ var recipeVersionCommand = cli.Command{
 | 
			
		||||
	Before:       internal.SubCommandBefore,
 | 
			
		||||
	BashComplete: autocomplete.RecipeNameComplete,
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		conf := runtime.New(runtime.WithOffline(internal.Offline))
 | 
			
		||||
		conf := runtime.New(
 | 
			
		||||
			runtime.WithOffline(internal.Offline),
 | 
			
		||||
			runtime.WithEnsureRecipeUpToDate(false),
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
		recipe := internal.ValidateRecipe(c, conf)
 | 
			
		||||
 | 
			
		||||
		catalogue, err := recipePkg.ReadRecipeCatalogue(conf)
 | 
			
		||||
 | 
			
		||||
@ -252,6 +252,11 @@ func Get(recipeName string, conf *runtime.Config) (Recipe, error) {
 | 
			
		||||
 | 
			
		||||
// EnsureExists ensures that a recipe is locally cloned
 | 
			
		||||
func EnsureExists(recipeName string, conf *runtime.Config) error {
 | 
			
		||||
	if !conf.RecipeExists {
 | 
			
		||||
		logrus.Debug("skipping ensuring recipe locally exists")
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	recipeDir := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
 | 
			
		||||
	if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
 | 
			
		||||
@ -339,6 +344,11 @@ func EnsureVersion(recipeName, version string) error {
 | 
			
		||||
 | 
			
		||||
// EnsureLatest makes sure the latest commit is checked out for a local recipe repository
 | 
			
		||||
func EnsureLatest(recipeName string, conf *runtime.Config) error {
 | 
			
		||||
	if !conf.RecipeLatest {
 | 
			
		||||
		logrus.Debug("skipping ensuring recipe is synced with remote")
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	recipeDir := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
 | 
			
		||||
	isClean, err := gitPkg.IsClean(recipeDir)
 | 
			
		||||
@ -584,6 +594,11 @@ func GetStringInBetween(recipeName, str, start, end string) (result string, err
 | 
			
		||||
 | 
			
		||||
// EnsureUpToDate ensures that the local repo is synced to the remote
 | 
			
		||||
func EnsureUpToDate(recipeName string, conf *runtime.Config) error {
 | 
			
		||||
	if !conf.RecipeLatest {
 | 
			
		||||
		logrus.Debug("skipping ensuring recipe is synced with remote")
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	recipeDir := path.Join(config.RECIPES_DIR, recipeName)
 | 
			
		||||
 | 
			
		||||
	isClean, err := gitPkg.IsClean(recipeDir)
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user