mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-10 20:40:40 +00:00
unlock on error and named arrays for config
This commit is contained in:
13
cmd/root.go
13
cmd/root.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user