fix self update path (#190)

This commit is contained in:
2022-04-27 00:43:47 +02:00
committed by GitHub
parent e43ab2dfd6
commit 985829800f
5 changed files with 12 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.autorestic.yml or ./.autorestic.yml)")
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")
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
cobra.OnInitialize(initConfig)
}

View File

@@ -16,6 +16,7 @@ import (
"github.com/blang/semver/v4"
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/colors"
"github.com/cupcakearmy/autorestic/internal/flags"
)
const INSTALL_PATH = "/usr/local/bin"
@@ -129,7 +130,7 @@ func InstallRestic() error {
func upgradeRestic() error {
_, _, err := internal.ExecuteCommand(internal.ExecuteOptions{
Command: "restic",
Command: flags.RESTIC_BIN,
}, "self-update")
return err
}

View File

@@ -185,7 +185,7 @@ func CheckConfig() error {
return fmt.Errorf("config could not be loaded/found")
}
if !CheckIfResticIsCallable() {
return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, RESTIC_BIN)
return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, flags.RESTIC_BIN)
}
for name, backend := range c.Backends {
backend.name = name

View File

@@ -1,5 +1,8 @@
package flags
var CI bool = false
var VERBOSE bool = false
var CRON_LEAN bool = false
var (
CI bool = false
VERBOSE bool = false
CRON_LEAN bool = false
RESTIC_BIN string
)

View File

@@ -12,15 +12,13 @@ import (
"github.com/fatih/color"
)
var RESTIC_BIN string
func CheckIfCommandIsCallable(cmd string) bool {
_, err := exec.LookPath(cmd)
return err == nil
}
func CheckIfResticIsCallable() bool {
return CheckIfCommandIsCallable(RESTIC_BIN)
return CheckIfCommandIsCallable(flags.RESTIC_BIN)
}
type ExecuteOptions struct {
@@ -79,7 +77,7 @@ func ExecuteCommand(options ExecuteOptions, args ...string) (int, string, error)
}
func ExecuteResticCommand(options ExecuteOptions, args ...string) (int, string, error) {
options.Command = RESTIC_BIN
options.Command = flags.RESTIC_BIN
var c = GetConfig()
var optionsAsString = getOptions(c.Global, []string{"all"})
args = append(optionsAsString, args...)