-
Notifications
You must be signed in to change notification settings - Fork 649
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
Conversation
691f8c0
to
77c20d4
Compare
There was a problem hiding this 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.
cmd/bbolt/command_check.go
Outdated
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 || args[0] == "" { | ||
return ErrPathRequired | ||
} | ||
if len(args) > 1 { | ||
return ErrTooManyArgs | ||
} | ||
return nil |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree that ExactArgs
can simplify the implementation. It's a generic problem, so it's OK to fix it separately.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raised #728
"go.etcd.io/bbolt/internal/btesting" | ||
) | ||
|
||
func TestCheckCommand_Run(t *testing.T) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍🏽
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments
There was a problem hiding this 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.
77c20d4
to
adfd9fd
Compare
adfd9fd
to
c5618e4
Compare
@ahrtr rebased and use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
c5618e4
to
10a2556
Compare
Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
10a2556
to
e3afa40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you!
Follow up to #698 (comment)
Linked to #580 && #472
cc @ahrtr @ivanvc @jmhbnz