Compare commits

..

10 Commits

Author SHA1 Message Date
75160d4d6a Merge pull request #160 from cupcakearmy/1.5.3
1.5.3
2022-02-16 21:29:10 +01:00
92feaef5bb version bump 2022-02-16 21:28:13 +01:00
2a7e233cdb only check on config if it is getting used 2022-02-16 21:22:42 +01:00
a373c07fb0 contrib 2022-02-13 16:25:51 +01:00
ec9e2aebcd 1.5.2 2022-02-13 16:25:09 +01:00
7d87160706 Merge pull request #156 from jjromannet/verbose-config-loading
Add error handling to reading of config file.
2022-02-13 16:23:05 +01:00
8e1fe6af65 Merge pull request #157 from jjromannet/fix-copy-config-file-before-overriding
Make a copy of config before overriding it
2022-02-13 16:20:46 +01:00
Jan
65ba1f6ac1 Make a copy of config before overriding it 2022-02-09 20:35:29 +01:00
Jan
6bf4953003 Add error handling to reading config file. 2022-02-09 20:26:02 +01:00
27758a03fa add help message 2021-12-22 14:45:04 +01:00
6 changed files with 59 additions and 24 deletions

View File

@@ -5,6 +5,19 @@ 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
### Fixed
- Error throwing not finding config even it's not being used.
## [1.5.2] - 2022-02-13
### Fixed
- Config loading @jjromannet
- Making a backup of the file @jjromannet
## [1.5.1] - 2021-12-06
### Changed

View File

@@ -3,6 +3,7 @@ package cmd
import (
"os"
"path/filepath"
"strings"
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/colors"
@@ -27,7 +28,7 @@ var rootCmd = &cobra.Command{
Version: internal.VERSION,
Use: "autorestic",
Short: "CLI Wrapper for restic",
Long: "Documentation: https://autorestic.vercel.app",
Long: "Documentation:\thttps://autorestic.vercel.app\nSupport:\thttps://discord.gg/wS7RpYTYd2",
}
func Execute() {
@@ -49,13 +50,21 @@ func initConfig() {
}
if cfgFile != "" {
if internal.VERBOSE {
colors.Faint.Printf("> Using config file: %s\n", cfgFile)
}
viper.SetConfigFile(cfgFile)
viper.AutomaticEnv()
if viper.ConfigFileUsed() == "" {
colors.Error.Println("cannot read config file %s\n", cfgFile)
os.Exit(1)
}
} else {
viper.AddConfigPath(".")
configPaths := []string{"."}
// Home
if home, err := homedir.Dir(); err != nil {
viper.AddConfigPath(home)
configPaths = append(configPaths, home)
}
// XDG_CONFIG_HOME
@@ -66,10 +75,17 @@ func initConfig() {
prefix = filepath.Join(home, ".config")
}
}
viper.AddConfigPath(filepath.Join(prefix, "autorestic"))
xdgConfig := filepath.Join(prefix, "autorestic")
configPaths = append(configPaths, xdgConfig)
}
viper.SetConfigName(".autorestic")
for _, cfgPath := range configPaths {
viper.AddConfigPath(cfgPath)
}
if internal.VERBOSE {
colors.Faint.Printf("Using config paths: %s\n", strings.Join(configPaths, " "))
}
cfgFileName := ".autorestic"
viper.SetConfigName(cfgFileName)
viper.AutomaticEnv()
}
}

View File

@@ -2,17 +2,18 @@
This amazing people helped the project!
- @agateblue - Docs, Pruning, S3
- @agateblue - Docs, Pruning, S3.
- @g-a-c - Update/Install bugs.
- @david-boles - Docs
- @SebDanielsson - Brew
- @n194 - AUR Package
- @jin-park-dev - Typos
- @sumnerboy12 - Typos
- @FuzzyMistborn - Typos
- @ChanceM - Typos
- @TheForcer - Typos
- @themorlan - Typos
- @somebox - Typos
- @jjromannet - Bug fixes.
- @david-boles - Docs.
- @SebDanielsson - Brew.
- @n194 - AUR Package.
- @jin-park-dev - Typos.
- @sumnerboy12 - Typos.
- @FuzzyMistborn - Typos.
- @ChanceM - Typos.
- @TheForcer - Typos.
- @themorlan - Typos.
- @somebox - Typos.
> :ToCPrevNext

View File

@@ -10,7 +10,7 @@ For remote backups (S3, B2, GCS, etc.) it's quite easy, as you only need to moun
docker run --rm \\
-v $(pwd):/data \\
cupcakearmy/autorestic \\
autorestic backup -va
autorestic backup -va -c /data/.autorestic.yaml
```
## Rclone

View File

@@ -16,7 +16,7 @@ import (
"github.com/spf13/viper"
)
const VERSION = "1.5.1"
const VERSION = "1.5.3"
var CI bool = false
var VERBOSE bool = false
@@ -63,7 +63,12 @@ func GetConfig() *Config {
}
}
} else {
return
cfgFileName := ".autorestic"
colors.Error.Println(
fmt.Sprintf(
"cannot find configuration file '%s.yml' or '%s.yaml'.",
cfgFileName, cfgFileName))
os.Exit(1)
}
var versionConfig interface{}
@@ -259,7 +264,7 @@ func (c *Config) SaveConfig() error {
if err := CopyFile(file, file+".old"); err != nil {
return err
}
colors.Secondary.Println("Saved a backup copy of your file next the the original.")
colors.Secondary.Println("Saved a backup copy of your file next to the original.")
viper.Set("backends", c.Backends)
viper.Set("locations", c.Locations)

View File

@@ -60,13 +60,13 @@ func ExecuteResticCommand(options ExecuteOptions, args ...string) (string, error
}
func CopyFile(from, to string) error {
original, err := os.Open("original.txt")
original, err := os.Open(from)
if err != nil {
return nil
}
defer original.Close()
new, err := os.Create("new.txt")
new, err := os.Create(to)
if err != nil {
return nil
}