mirror of
https://github.com/restic/restic.git
synced 2025-04-28 13:20:49 +00:00
Merge pull request #5327 from MichaelEischer/fix-forget-hostname-default
forget: fix ignored RESTIC_HOST environment variable
This commit is contained in:
commit
6684d1d2f5
7
changelog/unreleased/issue-5325
Normal file
7
changelog/unreleased/issue-5325
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Bugfix: Correctly handle `RESTIC_HOST` in `forget` command
|
||||||
|
|
||||||
|
The `forget` command did not use the host name from the `RESTIC_HOST`
|
||||||
|
environment variable. This has been fixed.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/5325
|
||||||
|
https://github.com/restic/restic/pull/5327
|
@ -137,13 +137,14 @@ func (opts *ForgetOptions) AddFlags(f *pflag.FlagSet) {
|
|||||||
f.Var(&opts.KeepTags, "keep-tag", "keep snapshots with this `taglist` (can be specified multiple times)")
|
f.Var(&opts.KeepTags, "keep-tag", "keep snapshots with this `taglist` (can be specified multiple times)")
|
||||||
f.BoolVar(&opts.UnsafeAllowRemoveAll, "unsafe-allow-remove-all", false, "allow deleting all snapshots of a snapshot group")
|
f.BoolVar(&opts.UnsafeAllowRemoveAll, "unsafe-allow-remove-all", false, "allow deleting all snapshots of a snapshot group")
|
||||||
|
|
||||||
initMultiSnapshotFilter(f, &opts.SnapshotFilter, false)
|
|
||||||
f.StringArrayVar(&opts.Hosts, "hostname", nil, "only consider snapshots with the given `hostname` (can be specified multiple times)")
|
f.StringArrayVar(&opts.Hosts, "hostname", nil, "only consider snapshots with the given `hostname` (can be specified multiple times)")
|
||||||
err := f.MarkDeprecated("hostname", "use --host")
|
err := f.MarkDeprecated("hostname", "use --host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// MarkDeprecated only returns an error when the flag is not found
|
// MarkDeprecated only returns an error when the flag is not found
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// must be defined after `--hostname` to not override the default value from the environment
|
||||||
|
initMultiSnapshotFilter(f, &opts.SnapshotFilter, false)
|
||||||
|
|
||||||
f.BoolVarP(&opts.Compact, "compact", "c", false, "use compact output format")
|
f.BoolVarP(&opts.Compact, "compact", "c", false, "use compact output format")
|
||||||
opts.GroupBy = restic.SnapshotGroupByOptions{Host: true, Path: true}
|
opts.GroupBy = restic.SnapshotGroupByOptions{Host: true, Path: true}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestForgetPolicyValues(t *testing.T) {
|
func TestForgetPolicyValues(t *testing.T) {
|
||||||
@ -92,3 +93,10 @@ func TestForgetOptionValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForgetHostnameDefaulting(t *testing.T) {
|
||||||
|
t.Setenv("RESTIC_HOST", "testhost")
|
||||||
|
opts := ForgetOptions{}
|
||||||
|
opts.AddFlags(pflag.NewFlagSet("test", pflag.ContinueOnError))
|
||||||
|
rtest.Equals(t, []string{"testhost"}, opts.Hosts)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user