From f29a28e0382feea9559ac841de9707db6223ed98 Mon Sep 17 00:00:00 2001 From: Joel Watson Date: Tue, 10 Nov 2020 10:55:30 -0600 Subject: [PATCH] Allow omission of -kvdetails if another -kv* flag is set --- command/snapshot/inspect/snapshot_inspect.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/command/snapshot/inspect/snapshot_inspect.go b/command/snapshot/inspect/snapshot_inspect.go index 3ddd30300..5c40c1c67 100644 --- a/command/snapshot/inspect/snapshot_inspect.go +++ b/command/snapshot/inspect/snapshot_inspect.go @@ -40,7 +40,7 @@ func (c *cmd) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags.BoolVar(&c.kvDetails, "kvdetails", false, "Provides a detailed KV space usage breakdown for any KV data that's been stored.") - c.flags.IntVar(&c.kvDepth, "kvdepth", 2, + c.flags.IntVar(&c.kvDepth, "kvdepth", 0, "Can only be used with -kvdetails. The key prefix depth used to breakdown KV store data. Defaults to 2.") c.flags.StringVar(&c.kvFilter, "kvfilter", "", "Can only be used with -kvdetails. Limits KV key breakdown using this prefix filter.") @@ -103,6 +103,20 @@ func (c *cmd) Run(args []string) int { return 1 } + // automatically set kvDetails to true if a depth or filter + // is provided. this allows the user to omit the -kvdetails + // flag if they prefer. + if c.kvDepth != 0 || c.kvFilter != "" { + c.kvDetails = true + } + + // set the default depth if one wasn't specified with -kvdepth. + // this is used rather than the flag default to facilitate the + // above shortcut. + if c.kvDetails && c.kvDepth == 0 { + c.kvDepth = 2 + } + // Open the file. f, err := os.Open(file) if err != nil {