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

Improves cmd descriptions and how terminal size is handled on oc help #10993

Merged

Conversation

fabianofranz
Copy link
Member

@fabianofranz fabianofranz commented Sep 19, 2016

Related to https://trello.com/c/04lpfTQR

We currently have a number of issues related to how the terminal width is recognized and used in the help (and actual command output) of oc. Some places like the flags section uses the entire terminal width, cmd descriptions limit the width but it's manual and not consistent between commands.

screenshot from 2016-09-19 12-27-45

This PR

  • Adds a new Writer that works in a responsive way by adjusting the help output according to the terminal size. Depending on the terminal width it will use 80, 100, or 120 columns as the max width, but not more than that given POSIX best practices and recommendations for better readability.
  • Adds markdown support to the cmd long descriptions, which allows us better control and normalization about how things like lists, paragraphs, line breaks, etc are printed.
  • Adds normalization to cmd examples.
  • Makes sure every command really uses the std and err outputs provided in the root commands, this is an issue today (only root-level commands are using it, anything under them in the cmd tree ignores the output provided to parents and use Stdout and Stderr).
  • Adds checks to guarantee all commands are following conventions.

Follow-ups

  • Upstream this
  • Reuse it from upstream (related: Reuse help templating from upstream #10957). We didn't do that yet because of the caveat of Usage at the bottom that kubectl uses, need to decide to either embrace it or add something like "help sections" that supports being reordered.
  • Adjust upstream commands descriptions to use LongDesc.
  • Use the responsive writer in all commands, not only help (need to check how it plays with tables like in get). We may still want wider output in some commands like that.

@openshift/cli-review @jwforres

@@ -27,15 +27,15 @@ import (
exipfailover "github.com/openshift/origin/pkg/cmd/experimental/ipfailover"
"github.com/openshift/origin/pkg/cmd/server/admin"
"github.com/openshift/origin/pkg/cmd/templates"
. "github.com/openshift/origin/pkg/cmd/templates"
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use ., just use templates.LongDesc.

I'd also prefer that we be using heredoc is combination with this, where you do auto unwrapping of paragraphs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, it's already a dependency and kube uses it in some cmds. I'll include heredoc to the normalization logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually better to use dedent. heredoc aligns with the smallest indentation present, meaning it can still leave indentation I don't want when doing the unwrap.

@smarterclayton
Copy link
Contributor

Get is moving to the server side so we'll be getting structured responses back (table of output). I think that'll probably be a similar use case, but different.

We really need wrapping with indentation to solve the large non help commands (long descriptions in describe). Can this do proper indentation?

return cmds
}

func setOutput(cmd *cobra.Command, out io.Writer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty drastic change - can you explain why this is necessary? Why would we not just require that all of the commands set output properly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Cascading the writer to the entire command tree would allow us, for example, to extend the use of the responsive writer for every command output (not just help) by setting it only in the root cmd.

Although it makes sense at a first glance, there are places (e.g. tables in get) where using the max width possible also probably makes sense, so I ended up not using this and only enabling the responsive writer in help.

I'll remove this block and let us set it individually in commands where we want it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed,

@fabianofranz fabianofranz force-pushed the 451_cli_usability_improvements branch 2 times, most recently from 4fc5e8d to f5f1c6e Compare September 19, 2016 20:09
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 20, 2016
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 3, 2016
@fabianofranz fabianofranz force-pushed the 451_cli_usability_improvements branch 3 times, most recently from d8e41d3 to 89e31f9 Compare October 5, 2016 00:45
@fabianofranz fabianofranz changed the title [WIP] Improves cmd descriptions and how terminal size in handled on oc help [WIP] Improves cmd descriptions and how terminal size is handled on oc help Oct 5, 2016
@fabianofranz fabianofranz force-pushed the 451_cli_usability_improvements branch 5 times, most recently from 1587637 to 4b4c5a5 Compare October 5, 2016 20:13
@fabianofranz fabianofranz changed the title [WIP] Improves cmd descriptions and how terminal size is handled on oc help Improves cmd descriptions and how terminal size is handled on oc help Oct 5, 2016
@fabianofranz
Copy link
Member Author

fabianofranz commented Oct 5, 2016

Removing WIP here, this is good to review @openshift/cli-review @smarterclayton @jwforres

Can this do proper indentation?

It doesn't fix the issue with indentation + long lines wrapping, but I don't think it would be hard to extend it to add something like that. It does, for example, proper indentation on multi-level lists, which is a similar concept.

@fabianofranz
Copy link
Member Author

[test]

@fabianofranz fabianofranz force-pushed the 451_cli_usability_improvements branch 6 times, most recently from ef0bd5d to 5309135 Compare October 7, 2016 14:53
@fabianofranz
Copy link
Member Author

Flaked on #9548 and #9490
re[test]

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2016
@fabianofranz
Copy link
Member Author

Upstreaming in kubernetes/kubernetes#34502.

@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 11, 2016
@fabianofranz
Copy link
Member Author

UP needs review

@fabianofranz
Copy link
Member Author

flake #11240 re[test]

1 similar comment
@fabianofranz
Copy link
Member Author

flake #11240 re[test]

@marun
Copy link
Contributor

marun commented Oct 14, 2016

flake #11374 re-[test]

@fabianofranz fabianofranz force-pushed the 451_cli_usability_improvements branch 2 times, most recently from 585cba3 to 0aaf947 Compare October 14, 2016 21:30
@fabianofranz
Copy link
Member Author

flake #11240 re[test]

@fabianofranz
Copy link
Member Author

Upstream merged, rebased here.
[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Oct 18, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10205/) (Image: devenv-rhel7_5206)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to fc72a9d

@fabianofranz
Copy link
Member Author

flake #11240 re[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to fc72a9d

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10205/) (Base Commit: a941850)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants