From 7448a15f720b270a1c18fce0a974af3c64329f3f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 28 Jul 2024 12:21:42 +0200 Subject: [PATCH] stats: add --mode completions --- cmd/restic/cmd_stats.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 8a78d57f7..60ab1e5bc 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -70,10 +70,20 @@ type StatsOptions struct { var statsOptions StatsOptions +func must(err error) { + if err != nil { + panic(fmt.Sprintf("error during setup: %v", err)) + } +} + func init() { cmdRoot.AddCommand(cmdStats) f := cmdStats.Flags() f.StringVar(&statsOptions.countMode, "mode", countModeRestoreSize, "counting mode: restore-size (default), files-by-contents, blobs-per-file or raw-data") + must(cmdStats.RegisterFlagCompletionFunc("mode", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + return []string{countModeRestoreSize, countModeUniqueFilesByContents, countModeBlobsPerFile, countModeRawData}, cobra.ShellCompDirectiveDefault + })) + initMultiSnapshotFilter(f, &statsOptions.SnapshotFilter, true) }