cleaner output and ctrl-c

This commit is contained in:
2021-04-12 16:15:17 +02:00
parent 640b60c47f
commit 3ccaee4066
10 changed files with 118 additions and 86 deletions

View File

@@ -6,6 +6,7 @@ import (
"strings"
"sync"
"github.com/cupcakearmy/autorestic/internal/colors"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -13,6 +14,9 @@ import (
const VERSION = "1.0.0"
var CI bool = false
var VERBOSE bool = false
type Config struct {
Locations []Location `mapstructure:"locations"`
Backends []Backend `mapstructure:"backends"`
@@ -24,6 +28,13 @@ var config *Config
func GetConfig() *Config {
if config == nil {
once.Do(func() {
if err := viper.ReadInConfig(); err == nil {
colors.Faint.Println("Using config file:", viper.ConfigFileUsed())
} else {
return
}
config = &Config{}
if err := viper.UnmarshalExact(config); err != nil {
panic(err)
@@ -45,6 +56,9 @@ func GetPathRelativeToConfig(p string) (string, error) {
}
func (c *Config) CheckConfig() error {
if c == nil {
return fmt.Errorf("config could not be loaded/found")
}
if !CheckIfResticIsCallable() {
return fmt.Errorf(`restic was not found. Install either with "autorestic install" or manually`)
}