Skip to content

Commit

Permalink
kv del and kv compact prompt for the bucket if not specified (just li…
Browse files Browse the repository at this point in the history
…ke stream del prompts you for the stream if not specified)

Signed-off-by: Jean-Noël Moyne <[email protected]>
  • Loading branch information
jnmoyne committed Oct 13, 2023
1 parent 3e7f02b commit 58632ec
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions cli/kv_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ for an indefinite period or a per-bucket configured TTL.
update.Arg("revision", "The revision of the previous value in the bucket").Uint64Var(&c.revision)

del := kv.Command("del", "Deletes a key or the entire bucket").Alias("rm").Action(c.deleteAction)
del.Arg("bucket", "The bucket to act on").Required().StringVar(&c.bucket)
del.Arg("bucket", "The bucket to act on").StringVar(&c.bucket)
del.Arg("key", "The key to act on").StringVar(&c.key)
del.Flag("force", "Act without confirmation").Short('f').UnNegatableBoolVar(&c.force)

Expand Down Expand Up @@ -149,7 +149,7 @@ for an indefinite period or a per-bucket configured TTL.
ls.Flag("display-value", "Display value in verbose output (has no effect without 'verbose')").UnNegatableBoolVar(&c.lsVerboseDisplayValue)

rmHistory := kv.Command("compact", "Reclaim space used by deleted keys").Action(c.compactAction)
rmHistory.Arg("bucket", "The bucket to act on").Required().StringVar(&c.bucket)
rmHistory.Arg("bucket", "The bucket to act on").StringVar(&c.bucket)
rmHistory.Flag("force", "Act without confirmation").Short('f').UnNegatableBoolVar(&c.force)
}

Expand Down Expand Up @@ -702,6 +702,33 @@ func (c *kvCommand) purgeAction(_ *fisk.ParseContext) error {
}

func (c *kvCommand) rmBucketAction(_ *fisk.ParseContext) error {
nc, js, err := prepareJSHelper()
if err != nil {
return err
}

if c.bucket == "" {
if c.bucket == "" {
known, err := c.knownBuckets(nc)
if err != nil {
return err
}

if len(known) == 0 {
return fmt.Errorf("no KV buckets found")
}

err = askOne(&survey.Select{
Message: "Select a Bucket",
Options: known,
PageSize: selectPageSize(len(known)),
}, &c.bucket)
if err != nil {
return err
}
}
}

if !c.force {
ok, err := askConfirmation(fmt.Sprintf("Delete bucket %s?", c.bucket), false)
if err != nil {
Expand All @@ -714,11 +741,6 @@ func (c *kvCommand) rmBucketAction(_ *fisk.ParseContext) error {
}
}

_, js, err := prepareJSHelper()
if err != nil {
return err
}

return js.DeleteKeyValue(c.bucket)
}

Expand Down

0 comments on commit 58632ec

Please sign in to comment.