Allow omission of -kvdetails if another -kv* flag is set

This commit is contained in:
Joel Watson 2020-11-10 10:55:30 -06:00
parent 1ef259b093
commit 40a8681816
1 changed files with 15 additions and 1 deletions

View File

@ -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 {