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

Add the ability to ls keys of a bucket #531

Merged
merged 3 commits into from
Aug 22, 2022

Conversation

dselans
Copy link
Contributor

@dselans dselans commented Jul 16, 2022

Needed the ability to easily list the keys in a bucket.

Probably doing something against convention - let me know if anything needs to be fixed up.

Thanks!

EDIT: Attached screenshot of what it looks like.
image

ls.Flag("names", "Show just the bucket names").Short('n').UnNegatableBoolVar(&c.listNames)
ls.Flag("verbose", "Show detailed info about the key").Short('v').BoolVar(&c.lsVerbose)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also be UnNegatableBoolVar, same with --display-value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Will do.

Copy link
Collaborator

@ripienaar ripienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor changes, thanks for adding this!

func (c *kvCommand) lsBucketKeys(mgr *jsm.Manager) error {
if mgr == nil {
return errors.New("mgr cannot be nil")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is only used internall and we know how we call it, and mgr setup failure already handled elsewhere I think this check can go - error would anyway not help users.

And actually mgr isnt used here at all so remove the argument I think, we can then move the call to create the mgr into lsBuckets as thats the only place its used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

keys, err := kv.Keys()
if err != nil {
if err == nats.ErrNoKeysFound {
return fmt.Errorf("no keys found in bucket %s", c.bucket)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is an error condition, see for example how we handle no streams, we just print a message and clean exit

fmt.Println("No Streams defined, pass -a to include system streams")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Will update.

@dselans dselans closed this Aug 16, 2022
@dselans dselans force-pushed the dselans/list_bucket_contents branch from 2ccbdce to 9a2b381 Compare August 16, 2022 03:31
@dselans dselans reopened this Aug 16, 2022
@dselans
Copy link
Contributor Author

dselans commented Aug 16, 2022

@ripienaar addressed your comments.

Copy link
Collaborator

@ripienaar ripienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit otherwise looks good thank you!

keys, err := kv.Keys()
if err != nil {
if err == nats.ErrNoKeysFound {
fmt.Printf("No keys found in bucket")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fmt.Println

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah! Sorry about that! Fixed.

@dselans dselans requested a review from ripienaar August 19, 2022 22:31
@ripienaar ripienaar merged commit 8780072 into nats-io:main Aug 22, 2022
@ripienaar
Copy link
Collaborator

Thank you

@dselans dselans deleted the dselans/list_bucket_contents branch August 22, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants