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

cmd: migrate check command to cobra style #723

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

Elbehery
Copy link
Member

Follow up to #698 (comment)
Linked to #580 && #472

cc @ahrtr @ivanvc @jmhbnz

@ahrtr
Copy link
Member

ahrtr commented Apr 15, 2024

@fuweid @ivanvc @tjungblu PTAL, thanks

Copy link
Member

@ivanvc ivanvc left a comment

Choose a reason for hiding this comment

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

I left two questions. The implementation looks good.

Comment on lines 27 to 40
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return ErrPathRequired
}
if len(args) > 1 {
return ErrTooManyArgs
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

This may actually be a question for @ahrtr. Is there any particular reason why we're not using https://pkg.go.dev/github.com/spf13/cobra#ExactArgs. I know that the surgery sub-commands do the check this same way. Is it to give more context to the error? i.e., rather than erroring with a wrong number of arguments, saying that the first argument needs to be a path?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's mostly a copy&paste thing :) We totally should use ExactArgs.

Copy link
Member

Choose a reason for hiding this comment

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

https://pkg.go.dev/github.com/spf13/cobra#ExactArgs.

Yes, I agree that ExactArgs can simplify the implementation. It's a generic problem, so it's OK to fix it separately.

Copy link
Member

Choose a reason for hiding this comment

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

Is it to give more context to the error? i.e., rather than erroring with a wrong number of arguments, saying that the first argument needs to be a path?

Once an error is returned, I think cobra will automatically print the usage, in which all info is included. So it seems that we don't need to provide any extra context.

Copy link
Member Author

Choose a reason for hiding this comment

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

raised #728

cmd/bbolt/main.go Outdated Show resolved Hide resolved
"go.etcd.io/bbolt/internal/btesting"
)

func TestCheckCommand_Run(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

while we're at it, can you add some test that exercises the corruption?

Copy link
Member

Choose a reason for hiding this comment

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

This PR just migrates the check command to cobra style. This comment is an enhancement request. It's OK to discuss it separately.

I think the purpose of CLI's test cases are just to verify the CLI itself instead of the functionalities. Also we already some test cases to verify the corrupted pages. FYI. https://github.com/etcd-io/bbolt/blob/main/tx_check_test.go

Copy link
Member Author

Choose a reason for hiding this comment

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

yes the corruption check has been test already, this test case just to verify the cli is working as expected 👍🏽

Copy link
Contributor

Choose a reason for hiding this comment

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

well, part of testing that CLI is also ensuring this case works. Feel free to do it as a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

i am confused now, so is this

This comment is an enhancement request

or just adding new test for the corruption check, because we already have tests for this https://github.com/etcd-io/bbolt/blob/main/tx_check_test.go

just to make sure we are all on the same page

Copy link
Contributor

@tjungblu tjungblu left a comment

Choose a reason for hiding this comment

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

left some comments

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

It's just migration and we can enhance it in the followup.

@Elbehery
Copy link
Member Author

@ahrtr rebased and use exactArgs 👍🏽

Copy link
Member

@ivanvc ivanvc left a comment

Choose a reason for hiding this comment

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

LGTM

cmd/bbolt/command_check.go Outdated Show resolved Hide resolved
cmd/bbolt/command_check.go Outdated Show resolved Hide resolved
cmd/bbolt/command_check.go Outdated Show resolved Hide resolved
Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you!

@ahrtr ahrtr merged commit df86a96 into etcd-io:main Apr 17, 2024
16 checks passed
@Elbehery Elbehery deleted the migrate_check_cobra branch April 22, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants