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 grouping for help message + streamlined help messages #887

Merged
merged 20 commits into from
Jun 18, 2020

Conversation

rhuss
Copy link
Contributor

@rhuss rhuss commented Jun 16, 2020

The top-level looks like

kn is the command line interface for managing Knative Serving and Eventing resources

 Find more information about Knative at: https://knative.dev

Serving Commands:
  service     Manage Knative services
  revision    Manage service revisions
  route       List and show service routes

Eventing Commands:
  source      Manage event sources
  trigger     Manage event triggers

Other Commands:
  plugin      Manage kn plugins
  completion  Output shell completion code
  version     Show the version of this client

Use "kn <command> --help" for more information about a given command.
Use "kn options" for a list of global command-line options (applies to all commands).

The following changes have been applied:

  • Add CommandGroups for grouping commands together
  • Add flexible templating for the help messages
  • Moved global options to an own command ('kn options', much like 'kubectl options')
  • Aligned wording and typography of help messages

These features has been highly inspired by kubectl grouping & help templating but has been considerably been stripped down to the needs of kn.

Fixes #579

The top-level looks like

kn is the command line interface for managing Knative Serving and Eventing objects

 Find more information about Knative at: https://knative.dev

Serving Commands:
  service     Manage Knative services
  revision    Manage service revisions
  route       List and show service routes

Eventing Commands:
  source      Manage event sources
  trigger     Manage event triggers

Other Commands:
  plugin      Manage kn plugins
  completion  Output shell completion code
  version     Show the version of this client

Use "kn <command> --help" for more information about a given command.
Use "kn options" for a list of global command-line options (applies to all commands).

The following changes have been applied:

* Add CommandGroups for grouping commands together
* Add flexible templating for the help messages
* Moved global options to an own command ('kn options', much like 'kubectl options')
* Aligned wording and typography of help messages

These features has been highly inspired by kubectl grouping & help templating but has been considerably been stripped down to the needs of kn.

Signed-off-by: Roland Huß <[email protected]>
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 16, 2020
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 16, 2020
@rhuss
Copy link
Contributor Author

rhuss commented Jun 16, 2020

Please note that testing still needs to be added, this PR is however already open for review to gather early feedback.

Copy link
Contributor

@danielhelfand danielhelfand left a comment

Choose a reason for hiding this comment

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

Tested locally for #885 and seems to resolve the issue.

Some general comments would be to check for error messages that already include the prefix to avoid double prints, such as here. Maybe that's handled, but in general should be removed and discouraged in the future.

Also, maybe including the error prefix in some tests is worthwhile as a means of verifying the error prefix?

Edit: I see the note on testing.

Looks good to me otherwise.

@rhuss
Copy link
Contributor Author

rhuss commented Jun 16, 2020

Some general comments would be to check for error messages that already include the prefix to avoid double prints, such as here. Maybe that's handled, but in general should be removed and discouraged in the future.

Since there is a single exit point we are free to mangle the error message as we want. But I consider this more like a workaround since adding an "error: " prefix in an error message looks quite redundant (it's clear that it is an error if the prefix is part of an error message, also the formatting of the error message should be left to the layer which deals with the error). However, we don't have much influence on the wording of errors returned from library calls.

I will add some tests to check the error wording.

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v wire_gen.go)

cmd/kn/main.go Outdated Show resolved Hide resolved
cmd/kn/main_test.go Outdated Show resolved Hide resolved
cmd/kn/main_test.go Outdated Show resolved Hide resolved
cmd/kn/main_test.go Outdated Show resolved Hide resolved
@rhuss
Copy link
Contributor Author

rhuss commented Jun 17, 2020

Added the missing testing bits.

@navidshaikh
Copy link
Collaborator

/assign

@rhuss
Copy link
Contributor Author

rhuss commented Jun 17, 2020

/retest

pkg/kn/commands/completion/completion.go Outdated Show resolved Hide resolved
pkg/kn/commands/source/apiserver/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/list.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/route/route.go Outdated Show resolved Hide resolved
pkg/kn/commands/revision/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/revision/delete.go Outdated Show resolved Hide resolved
pkg/kn/commands/plugin/plugin.go Outdated Show resolved Hide resolved
cmd/kn/main_test.go Show resolved Hide resolved
pkg/templates/command_groups.go Outdated Show resolved Hide resolved
pkg/templates/command_groups.go Outdated Show resolved Hide resolved
rootCmd.SetHelpFunc(engine.helpFunc())
}

func setHelpFlagsToSubCommands(parent *cobra.Command) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is removing [flags] from the usage line, we may rename this to disableFlagsInUseLine ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it adds "[options]" instead of "[flags]" --> https://github.com/rhuss/knative-client/blob/41338722cdc2124dda2b3a594527749a31d8b735/pkg/templates/template_engine.go#L134

Again, inline with kubectl and "options" is a good wording here, as all the rest is just optional. Everything mandatory should be mentioned in the "Use" attribute.

pkg/templates/templates.go Show resolved Hide resolved
@maximilien
Copy link
Contributor

/test pull-knative-client-integration-tests-latest-release

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.

Overall looks good. I like the consolidations and some simplication though there are various places where text is repeated and/or not adding anything useful, perhaps best to omit or remove, .e.g, Synopis of source apiserver and various places. Left a few other specific comments.

Did not review the templating section. I see that @navidshaikh is reviewing. I might take a pass after.


### Synopsis

Provides utilities for interacting and managing with kn plugins.
Manage kn plugins
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also mention the client-contrib here as a place to find "vetted" plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 for this but maybe we should have a first release for the client-contrib plugins. We can add this info any time with a link to a consolidated list.

@@ -1,13 +1,13 @@
## kn source apiserver list
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this read: "## kn source api-server list" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comment below.


### Synopsis

Delete a sink binding.
Delete a sink binding
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder how useful the Synopsis is when its the same text as the general description?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is due to the way how the docs are generated and that the BindingDeleteCommand doesn't have a Long description (so the short description is reused).

We should add to every command a longer descriptions (if it makes sense, here e.g. one could add a brief explanation what a sink binding is, maybe with a link to the binding docs).

As this PR doesn't change anything with regard to the Long description, I'd suggest to open a new issue for this and work separately on consolidating the long descriptions.

@@ -26,8 +26,8 @@ import (
// NewAPIServerCommand for managing ApiServer source
func NewAPIServerCommand(p *commands.KnParams) *cobra.Command {
apiServerSourceCmd := &cobra.Command{
Use: "apiserver",
Short: "Kubernetes API Server Event Source command group",
Use: "apiserver COMMAND",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be api-server COMMAND?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We settled on apiserver for the command (like in kn source apiserver list), so changing it now would be backwards incompatible. We could do this if its improve the UX considerably but should be aware that it involves more work than just renaming it here.

What we can do though is to add an alias api-server for apiserver alongside the suggestions in #812 .

Copy link
Collaborator

Choose a reason for hiding this comment

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

:+1 for alias

type StdoutCapture struct {
r, w *os.File
t *testing.T
type OutputCapture struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this testing_helper.go should move to lib/test to make it useable in client-contrib plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, going to move it over there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved the OutputCapture to lib/test.

I think the other parts are more for internally testing KnCommands that is specific of how kn organizes it commands (also there might be some change here, too).

@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
cmd/kn/main.go 77.0% 78.1% 1.0
pkg/kn/commands/testing_helper.go 91.1% 87.9% -3.2
pkg/kn/root/root.go 87.2% 89.7% 2.5
pkg/templates/command_groups.go Do not exist 90.9%
pkg/templates/template_engine.go Do not exist 87.5%
pkg/templates/templates.go Do not exist 100.0%

Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

/retest
/lgtm
/approve

thanks!
aliases could be the next thing to look at..

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh, 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

@navidshaikh
Copy link
Collaborator

@rhuss : CHANGELOG missing, lets bring it in another PR

@knative-prow-robot knative-prow-robot merged commit b916a5b into knative:master Jun 18, 2020
@rhuss
Copy link
Contributor Author

rhuss commented Jun 18, 2020

Thanks !

dsimansk pushed a commit to dsimansk/client that referenced this pull request May 3, 2022
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split eventing/serving commands in help message to increase discoverability
8 participants