2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-11 05:12:21 +00:00

Merge pull request #718 from mholt/flag-priority

CLI options now override env vars
This commit is contained in:
Alexander Neumann 2017-01-02 20:31:20 +01:00
commit 4a6086a14b
2 changed files with 8 additions and 18 deletions

View File

@ -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,18 +25,6 @@ import (
var version = "compiled manually" var version = "compiled manually"
func parseEnvironment(cmd *cobra.Command, args []string) {
repo := os.Getenv("RESTIC_REPOSITORY")
if repo != "" {
globalOptions.Repo = repo
}
pw := os.Getenv("RESTIC_PASSWORD")
if pw != "" {
globalOptions.password = pw
}
}
// GlobalOptions hold all global options for restic. // GlobalOptions hold all global options for restic.
type GlobalOptions struct { type GlobalOptions struct {
Repo string Repo string
@ -57,8 +43,13 @@ var globalOptions = GlobalOptions{
} }
func init() { func init() {
pw := os.Getenv("RESTIC_PASSWORD")
if pw != "" {
globalOptions.password = pw
}
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", os.Getenv("RESTIC_REPOSITORY"), "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")
f.BoolVarP(&globalOptions.Quiet, "quiet", "q", false, "do not outputcomprehensive progress report") f.BoolVarP(&globalOptions.Quiet, "quiet", "q", false, "do not outputcomprehensive progress report")
f.BoolVar(&globalOptions.NoLock, "no-lock", false, "do not lock the repo, this allows some operations on read-only repos") f.BoolVar(&globalOptions.NoLock, "no-lock", false, "do not lock the repo, this allows some operations on read-only repos")

View 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() {