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

Fix kn source -h #846

Merged
merged 1 commit into from
Jun 2, 2020
Merged

Conversation

danielhelfand
Copy link
Contributor

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 in HandlePluginCommand
  • Add test

Reference

Fixes #845

/lint

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 18, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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 in HandlePluginCommand
  • 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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 18, 2020
@knative-prow-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 18, 2020
@rhuss
Copy link
Contributor

rhuss commented May 19, 2020

Thanks for the PR ! Could you a bit elaborate on your use case ? I'm asking because I think that a

kn --help admin should be the same as kn admin --help and print out the help message of the plugin itself (i.e. executing kn-admin --help). So I think checking for a valid plugin makes sense and only if no or an invalid plugin is given then print out the help (+ an error message if an unknown command/plugin is specified).

@rhuss
Copy link
Contributor

rhuss commented May 19, 2020

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 19, 2020
@danielhelfand
Copy link
Contributor Author

danielhelfand commented May 19, 2020

So I think checking for a valid plugin makes sense and only if no or an invalid plugin is given then print out the help (+ an error message if an unknown command/plugin is specified).

Thanks for the explanation. My apologies for the original attempt as I am not fully familiar with kn's plugin strategy. I pushed up a change that I think addresses this, but let me know if there are use cases I am not considering here.

Basically, instead of returning an error for if len(foundBinaryPath) == 0, move that check to before attempting to execute the plugin. If the plugin is invalid, the execution returns an error.

if len(foundBinaryPath) != 0 {
    err := pluginHandler.Execute(foundBinaryPath, append([]string{foundBinaryPath}, cmdArgs[len(remainingArgs):]...), os.Environ())
    if err != nil {
        return err
    }
}

@@ -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() {
Copy link
Contributor Author

@danielhelfand danielhelfand May 19, 2020

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.

Copy link
Contributor

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.

@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 19, 2020
@rhuss
Copy link
Contributor

rhuss commented May 19, 2020

Thanks! I will have a look tomorrow but maybe we should wait until #834 is merged as I think it can conflict.

Copy link
Contributor

@maximilien maximilien left a 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

@@ -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() {
Copy link
Contributor

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.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/core/root.go 51.7% 52.8% 1.1

@rhuss
Copy link
Contributor

rhuss commented May 27, 2020

@danielhelfand I think there is still a mismatch in the assertion of the e2e test (see test failure). Could you have a look please ?

@rhuss
Copy link
Contributor

rhuss commented Jun 1, 2020

@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.

@danielhelfand danielhelfand force-pushed the source_help branch 2 times, most recently from 4f2beb7 to 1124015 Compare June 1, 2020 15:54
@danielhelfand
Copy link
Contributor Author

danielhelfand commented Jun 1, 2020

@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")
Copy link
Contributor Author

@danielhelfand danielhelfand Jun 1, 2020

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.

Copy link
Contributor

@rhuss rhuss left a 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

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 2, 2020
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 2, 2020
@knative-prow-robot knative-prow-robot merged commit 834ee79 into knative:master Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kn source -h Returns Error: unknown command 'source'
6 participants