From 5d58945718dfaf2ee7946542eb26b69c8cca8fb0 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 27 Aug 2024 13:48:31 +0200 Subject: [PATCH] cleanup include / exclude option setup --- cmd/restic/cmd_backup.go | 2 +- cmd/restic/cmd_restore.go | 4 ++-- cmd/restic/cmd_rewrite.go | 2 +- cmd/restic/exclude.go | 2 +- cmd/restic/include.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index ceb7694b1..8d72a27b0 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -108,7 +108,7 @@ func init() { f.VarP(&backupOptions.GroupBy, "group-by", "g", "`group` snapshots by host, paths and/or tags, separated by comma (disable grouping with '')") f.BoolVarP(&backupOptions.Force, "force", "f", false, `force re-reading the source files/directories (overrides the "parent" flag)`) - initExcludePatternOptions(f, &backupOptions.excludePatternOptions) + backupOptions.excludePatternOptions.Add(f) f.BoolVarP(&backupOptions.ExcludeOtherFS, "one-file-system", "x", false, "exclude other file systems, don't cross filesystem boundaries and subvolumes") f.StringArrayVar(&backupOptions.ExcludeIfPresent, "exclude-if-present", nil, "takes `filename[:header]`, exclude contents of directories containing filename (except filename itself) if header of that file is as provided (can be specified multiple times)") diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index c58b0b80d..f20359dc0 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -68,8 +68,8 @@ func init() { flags := cmdRestore.Flags() flags.StringVarP(&restoreOptions.Target, "target", "t", "", "directory to extract data to") - initExcludePatternOptions(flags, &restoreOptions.excludePatternOptions) - initIncludePatternOptions(flags, &restoreOptions.includePatternOptions) + restoreOptions.excludePatternOptions.Add(flags) + restoreOptions.includePatternOptions.Add(flags) initSingleSnapshotFilter(flags, &restoreOptions.SnapshotFilter) flags.BoolVar(&restoreOptions.DryRun, "dry-run", false, "do not write any data, just show what would be done") diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 7788016b7..fc9da5b60 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -103,7 +103,7 @@ func init() { f.StringVar(&rewriteOptions.Metadata.Time, "new-time", "", "replace time of the backup") initMultiSnapshotFilter(f, &rewriteOptions.SnapshotFilter, true) - initExcludePatternOptions(f, &rewriteOptions.excludePatternOptions) + rewriteOptions.excludePatternOptions.Add(f) } type rewriteFilterFunc func(ctx context.Context, sn *restic.Snapshot) (restic.ID, error) diff --git a/cmd/restic/exclude.go b/cmd/restic/exclude.go index 40eb93933..a37f9c68e 100644 --- a/cmd/restic/exclude.go +++ b/cmd/restic/exclude.go @@ -130,7 +130,7 @@ type excludePatternOptions struct { InsensitiveExcludeFiles []string } -func initExcludePatternOptions(f *pflag.FlagSet, opts *excludePatternOptions) { +func (opts *excludePatternOptions) Add(f *pflag.FlagSet) { f.StringArrayVarP(&opts.Excludes, "exclude", "e", nil, "exclude a `pattern` (can be specified multiple times)") f.StringArrayVar(&opts.InsensitiveExcludes, "iexclude", nil, "same as --exclude `pattern` but ignores the casing of filenames") f.StringArrayVar(&opts.ExcludeFiles, "exclude-file", nil, "read exclude patterns from a `file` (can be specified multiple times)") diff --git a/cmd/restic/include.go b/cmd/restic/include.go index dcc4c7f37..514a24016 100644 --- a/cmd/restic/include.go +++ b/cmd/restic/include.go @@ -19,7 +19,7 @@ type includePatternOptions struct { InsensitiveIncludeFiles []string } -func initIncludePatternOptions(f *pflag.FlagSet, opts *includePatternOptions) { +func (opts *includePatternOptions) Add(f *pflag.FlagSet) { f.StringArrayVarP(&opts.Includes, "include", "i", nil, "include a `pattern` (can be specified multiple times)") f.StringArrayVar(&opts.InsensitiveIncludes, "iinclude", nil, "same as --include `pattern` but ignores the casing of filenames") f.StringArrayVar(&opts.IncludeFiles, "include-file", nil, "read include patterns from a `file` (can be specified multiple times)")