-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fix kn source -h #846
Fix kn source -h #846
Conversation
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.
@danielhelfand: 0 warnings.
In response to this:
Description
This pull request adds a check for if
-h
or--help
is specified with a plugin command. There should be no need to check for plugin executable availability if--help
is specified and will avoid an error being returned that a command does not exist as documented in #845.Changes
- Add check for if
-h
or--help
is specified inHandlePluginCommand
- Add test
Reference
Fixes #845
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Hi @danielhelfand. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Thanks for the PR ! Could you a bit elaborate on your use case ? I'm asking because I think that a
|
/ok-to-test |
4ecc502
to
b9e123c
Compare
Thanks for the explanation. My apologies for the original attempt as I am not fully familiar with Basically, instead of returning an error for if len(foundBinaryPath) != 0 {
err := pluginHandler.Execute(foundBinaryPath, append([]string{foundBinaryPath}, cmdArgs[len(remainingArgs):]...), os.Environ())
if err != nil {
return err
}
} |
b9e123c
to
287c591
Compare
pkg/kn/core/root.go
Outdated
@@ -87,7 +87,8 @@ func NewDefaultKnCommandWithArgs(rootCmd *cobra.Command, | |||
fmt.Fprintf(rootCmd.OutOrStderr(), "Error: unknown command '%s' \nRun 'kn --help' for usage.\n", args[1]) | |||
os.Exit(1) | |||
} | |||
} else if foundCmd.HasSubCommands() { | |||
} | |||
if foundCmd.HasSubCommands() { |
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 can either be kept as an else if
and checking would need to be done in the if
block so an error is still returned if the subcommand is invalid, or it can be checked each time as its own block.
The change here would result in command suggestions being shown in addition to the error, which I think is helpful, but I don't have a strong opinion on it:
$ ./kn rev
Error: unknown subcommand 'rev' for 'kn'.
Available subcommands: completion, help, plugin, revision, route, service, source, trigger, version
Run 'kn --help' for usage.
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.
Thanks. I actually also had a fix in my pending PR for allowing extending all subcommands groups. But thanks for submitting this. I’ll merge mine.
287c591
to
0fdbe07
Compare
0fdbe07
to
02af555
Compare
Thanks! I will have a look tomorrow but maybe we should wait until #834 is merged as I think it can conflict. |
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.
Looks good. I would also add a small e2e test for help with -h
With and without the source subcommand. Otherwise LGTM
pkg/kn/core/root.go
Outdated
@@ -87,7 +87,8 @@ func NewDefaultKnCommandWithArgs(rootCmd *cobra.Command, | |||
fmt.Fprintf(rootCmd.OutOrStderr(), "Error: unknown command '%s' \nRun 'kn --help' for usage.\n", args[1]) | |||
os.Exit(1) | |||
} | |||
} else if foundCmd.HasSubCommands() { | |||
} | |||
if foundCmd.HasSubCommands() { |
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.
Thanks. I actually also had a fix in my pending PR for allowing extending all subcommands groups. But thanks for submitting this. I’ll merge mine.
The following is the coverage report on the affected files.
|
@danielhelfand I think there is still a mismatch in the assertion of the e2e test (see test failure). Could you have a look please ? |
@danielhelfand would it be possible that we get this PR merged until tomorrow? I'm asking because I'm planning a bigger refactoring in this area (mostly because for implementing #579 and plugin help messages). If not, it could be that we later have to change this PR considerably because of conflicts which are likely. Also, tomorrow the next release will be cut, so would be cool if we could get that feature in. |
4f2beb7
to
1124015
Compare
1124015
to
a5cb0a4
Compare
@rhuss Should be fixed with some minor tweaks I'll point out in review message. Let me know if there's any additional changes you would like, and I can address today. Thanks! |
@@ -77,12 +77,11 @@ func TestWrongCommand(t *testing.T) { | |||
r := test.NewKnRunResultCollector(t, it) | |||
defer r.DumpIfFailed() | |||
|
|||
out := test.Kn{}.Run("source", "apiserver", "noverb", "--tag=0.13") |
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.
Seems with changes that flag validation is taking place, so error was coming back saying --tag
is not a valid flag for kn source apiserver
, which is valid since there is no --tag
flag. I removed --tag
for now.
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.
thanks, let's get that merge. Also to avoid conflicts later when I work on refactoring the help message for grouping.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: danielhelfand, rhuss The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
This pull request adds a check for if
-h
or--help
is specified with a plugin command. There should be no need to check for plugin executable availability if--help
is specified and will avoid an error being returned that a command does not exist as documented in #845.Changes
-h
or--help
is specified inHandlePluginCommand
Reference
Fixes #845
/lint