unlock on error and named arrays for config

This commit is contained in:
2021-04-11 17:02:34 +02:00
parent 8a1fe41825
commit 6e25b90915
14 changed files with 138 additions and 49 deletions

View File

@@ -20,12 +20,21 @@ import (
"os"
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/lock"
"github.com/spf13/cobra"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
func CheckErr(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
lock.Unlock()
os.Exit(1)
}
}
var cfgFile string
// rootCmd represents the base command when called without any subcommands
@@ -38,7 +47,7 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.CheckErr(rootCmd.Execute())
CheckErr(rootCmd.Execute())
}
func init() {
@@ -63,7 +72,7 @@ func initConfig() {
} else {
// Find home directory.
home, err := homedir.Dir()
cobra.CheckErr(err)
CheckErr(err)
viper.AddConfigPath(".")
viper.AddConfigPath(home)