forked from TrueCloudLab/restic
CLI options now override env vars
This commit is contained in:
parent
f9501e97a2
commit
a394b675b0
2 changed files with 4 additions and 6 deletions
|
@ -10,8 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"restic/backend/local"
|
"restic/backend/local"
|
||||||
"restic/backend/rest"
|
"restic/backend/rest"
|
||||||
"restic/backend/s3"
|
"restic/backend/s3"
|
||||||
|
@ -27,7 +25,7 @@ import (
|
||||||
|
|
||||||
var version = "compiled manually"
|
var version = "compiled manually"
|
||||||
|
|
||||||
func parseEnvironment(cmd *cobra.Command, args []string) {
|
func parseEnvironment() {
|
||||||
repo := os.Getenv("RESTIC_REPOSITORY")
|
repo := os.Getenv("RESTIC_REPOSITORY")
|
||||||
if repo != "" {
|
if repo != "" {
|
||||||
globalOptions.Repo = repo
|
globalOptions.Repo = repo
|
||||||
|
@ -57,6 +55,7 @@ var globalOptions = GlobalOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
parseEnvironment()
|
||||||
f := cmdRoot.PersistentFlags()
|
f := cmdRoot.PersistentFlags()
|
||||||
f.StringVarP(&globalOptions.Repo, "repo", "r", "", "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
|
f.StringVarP(&globalOptions.Repo, "repo", "r", "", "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
|
||||||
f.StringVarP(&globalOptions.PasswordFile, "password-file", "p", "", "read the repository password from a file")
|
f.StringVarP(&globalOptions.PasswordFile, "password-file", "p", "", "read the repository password from a file")
|
||||||
|
|
|
@ -20,9 +20,8 @@ var cmdRoot = &cobra.Command{
|
||||||
restic is a backup program which allows saving multiple revisions of files and
|
restic is a backup program which allows saving multiple revisions of files and
|
||||||
directories in an encrypted repository stored on different backends.
|
directories in an encrypted repository stored on different backends.
|
||||||
`,
|
`,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
PersistentPreRun: parseEnvironment,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue