Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt for bucket if not specified #899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading