diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c7fc0..91e613e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.5.3] - 2022-02-13 +## [1.5.4] - 2022-02-16 + +### Fixed + +- Lean flag not omitting all output. + +## [1.5.3] - 2022-02-16 ### Fixed diff --git a/cmd/cron.go b/cmd/cron.go index 5ea0c7f..269a70b 100644 --- a/cmd/cron.go +++ b/cmd/cron.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/cupcakearmy/autorestic/internal" + "github.com/cupcakearmy/autorestic/internal/flags" "github.com/cupcakearmy/autorestic/internal/lock" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ var cronCmd = &cobra.Command{ Long: `Intended to be mainly triggered by an automated system like systemd or crontab. For each location checks if a cron backup is due and runs it.`, Run: func(cmd *cobra.Command, args []string) { internal.GetConfig() - internal.CRON_LEAN, _ = cmd.Flags().GetBool("lean") + flags.CRON_LEAN, _ = cmd.Flags().GetBool("lean") err := lock.Lock() CheckErr(err) defer lock.Unlock() diff --git a/cmd/root.go b/cmd/root.go index c6f9b41..ae73f52 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,6 +7,7 @@ import ( "github.com/cupcakearmy/autorestic/internal" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" "github.com/cupcakearmy/autorestic/internal/lock" "github.com/spf13/cobra" @@ -37,8 +38,8 @@ func Execute() { func init() { rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.autorestic.yml or ./.autorestic.yml)") - rootCmd.PersistentFlags().BoolVar(&internal.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity") - rootCmd.PersistentFlags().BoolVarP(&internal.VERBOSE, "verbose", "v", false, "verbose mode") + rootCmd.PersistentFlags().BoolVar(&flags.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity") + rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode") rootCmd.PersistentFlags().StringVar(&internal.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary") cobra.OnInitialize(initConfig) } @@ -46,13 +47,10 @@ func init() { func initConfig() { if ci, _ := rootCmd.Flags().GetBool("ci"); ci { colors.DisableColors(true) - internal.VERBOSE = true + flags.VERBOSE = true } if cfgFile != "" { - if internal.VERBOSE { - colors.Faint.Printf("> Using config file: %s\n", cfgFile) - } viper.SetConfigFile(cfgFile) viper.AutomaticEnv() if viper.ConfigFileUsed() == "" { @@ -81,7 +79,7 @@ func initConfig() { for _, cfgPath := range configPaths { viper.AddConfigPath(cfgPath) } - if internal.VERBOSE { + if flags.VERBOSE { colors.Faint.Printf("Using config paths: %s\n", strings.Join(configPaths, " ")) } cfgFileName := ".autorestic" diff --git a/internal/backend.go b/internal/backend.go index 69cd5f8..ebb004d 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" ) type BackendRest struct { @@ -128,7 +129,7 @@ func (b Backend) validate() error { // If not initialize colors.Body.Printf("Initializing backend \"%s\"...\n", b.name) out, err := ExecuteResticCommand(options, "init") - if VERBOSE { + if flags.VERBOSE { colors.Faint.Println(out) } return err @@ -146,7 +147,7 @@ func (b Backend) Exec(args []string) error { colors.Error.Println(out) return err } - if VERBOSE { + if flags.VERBOSE { colors.Faint.Println(out) } return nil diff --git a/internal/config.go b/internal/config.go index f7b25b4..c4a8f00 100644 --- a/internal/config.go +++ b/internal/config.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" "github.com/cupcakearmy/autorestic/internal/lock" "github.com/joho/godotenv" "github.com/mitchellh/go-homedir" @@ -16,11 +17,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.5.3" - -var CI bool = false -var VERBOSE bool = false -var CRON_LEAN bool = false +const VERSION = "1.5.4" type OptionMap map[string][]interface{} type Options map[string]OptionMap @@ -52,15 +49,15 @@ func GetConfig() *Config { if config == nil { once.Do(func() { if err := viper.ReadInConfig(); err == nil { - if !CRON_LEAN { - absConfig, _ := filepath.Abs(viper.ConfigFileUsed()) + absConfig, _ := filepath.Abs(viper.ConfigFileUsed()) + if !flags.CRON_LEAN { colors.Faint.Println("Using config: \t", absConfig) - // Load env file - envFile := filepath.Join(filepath.Dir(absConfig), ".autorestic.env") - err = godotenv.Load(envFile) - if err == nil { - colors.Faint.Println("Using env:\t", envFile) - } + } + // Load env file + envFile := filepath.Join(filepath.Dir(absConfig), ".autorestic.env") + err = godotenv.Load(envFile) + if err == nil { + colors.Faint.Println("Using env:\t", envFile) } } else { cfgFileName := ".autorestic" diff --git a/internal/flags/flags.go b/internal/flags/flags.go new file mode 100644 index 0000000..ac7fc3a --- /dev/null +++ b/internal/flags/flags.go @@ -0,0 +1,5 @@ +package flags + +var CI bool = false +var VERBOSE bool = false +var CRON_LEAN bool = false diff --git a/internal/location.go b/internal/location.go index b94b916..45af39c 100644 --- a/internal/location.go +++ b/internal/location.go @@ -9,6 +9,7 @@ import ( "time" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" "github.com/cupcakearmy/autorestic/internal/lock" "github.com/cupcakearmy/autorestic/internal/metadata" "github.com/robfig/cron" @@ -108,7 +109,7 @@ func (l Location) ExecuteHooks(commands []string, options ExecuteOptions) error colors.Error.Println(out) return err } - if VERBOSE { + if flags.VERBOSE { colors.Faint.Println(out) } } @@ -227,7 +228,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error { options.Envs[k+"_"+fmt.Sprint(i)] = v options.Envs[k+"_"+strings.ToUpper(backend.name)] = v } - if VERBOSE { + if flags.VERBOSE { colors.Faint.Println(out) } } @@ -276,7 +277,7 @@ func (l Location) Forget(prune bool, dry bool) error { } cmd = append(cmd, combineOptions("forget", l, backend)...) out, err := ExecuteResticCommand(options, cmd...) - if VERBOSE { + if flags.VERBOSE { colors.Faint.Println(out) } if err != nil { @@ -367,7 +368,7 @@ func (l Location) RunCron() error { lock.SetCron(l.name, now.Unix()) l.Backup(true, "") } else { - if !CRON_LEAN { + if !flags.CRON_LEAN { colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) } } diff --git a/internal/lock/lock.go b/internal/lock/lock.go index b07727b..4667cb1 100644 --- a/internal/lock/lock.go +++ b/internal/lock/lock.go @@ -6,6 +6,7 @@ import ( "sync" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" "github.com/spf13/viper" ) @@ -25,7 +26,9 @@ func getLock() *viper.Viper { os.Exit(1) } file = path.Join(path.Dir(p), ".autorestic.lock.yml") - colors.Faint.Println("Using lock:\t", file) + if !flags.CRON_LEAN { + colors.Faint.Println("Using lock:\t", file) + } lock.SetConfigFile(file) lock.SetConfigType("yml") lock.ReadInConfig() diff --git a/internal/utils.go b/internal/utils.go index 302df2e..de6b167 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -8,6 +8,7 @@ import ( "os/exec" "github.com/cupcakearmy/autorestic/internal/colors" + "github.com/cupcakearmy/autorestic/internal/flags" ) var RESTIC_BIN string @@ -36,7 +37,7 @@ func ExecuteCommand(options ExecuteOptions, args ...string) (string, error) { cmd.Env = env cmd.Dir = options.Dir - if VERBOSE { + if flags.VERBOSE { colors.Faint.Printf("> Executing: %s\n", cmd) }