Skip to content

Add "reference" help topic#2223

Merged
vilmibm merged 14 commits intocli:trunkfrom
rista404:cmd-reference-1734
Nov 18, 2020
Merged

Add "reference" help topic#2223
vilmibm merged 14 commits intocli:trunkfrom
rista404:cmd-reference-1734

Conversation

@rista404
Copy link
Contributor

Hello! I tried to keep the reference simple and in line with the manual. Let me know if I need to change anything!

image

Closes #1734

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

This looks really cool! Hvala @rista404 for working on this 💖

@vilmibm vilmibm self-requested a review November 3, 2020 00:30
vilmibm
vilmibm previously requested changes Nov 3, 2020
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

This is really cool! Thank you!

Please update this so it is accessed via gh help reference instead of having it print as part of gh help or as usage information. It's too much information to print in those cases but is a great help topic.

@rista404
Copy link
Contributor Author

rista404 commented Nov 4, 2020

@vilmibm totally missed that it is printed in gh help also! Fixed it.

@rista404 rista404 requested a review from vilmibm November 4, 2020 11:45
@vilmibm
Copy link
Contributor

vilmibm commented Nov 4, 2020

We just merged some stuff that breaks this; I'm going to push some commits to fix it so it can be merged.

@vilmibm vilmibm force-pushed the cmd-reference-1734 branch from 4aa7530 to 0ccdae1 Compare November 4, 2020 21:04
@vilmibm
Copy link
Contributor

vilmibm commented Nov 4, 2020

for posterity: there was an internal concern about generating this on every invocation of gh; I ran a ton of benchmarks on my machine using a non-networked command and there was no meaningful effect on performance from having this in.

@Okeakwalam27

This comment was marked as spam.

@vilmibm
Copy link
Contributor

vilmibm commented Nov 4, 2020

While I'm still in favor of merging this as it's very useful from the command line (gh help reference) it unfortunately does not survive the translation to markdown well for use on the manual site; it ends up being very garbled with all formatting and indentation lost.

I see three options:

  • porting this to generate markdown (instead of directly using ColorScheme functions) and then running it through glamour
  • porting it to generate markdown and printing the raw markdown on the CLI
  • tweaking the formatting so it looks at least intelligible when it becomes markdown

I'm leaning towards the first option; in general the help topic system is meant to do double duty of CLI and HTML help and we're only going to want more markdown formatting in help topics, not less.

I'm happy to augment this to output markdown.

@vilmibm
Copy link
Contributor

vilmibm commented Nov 9, 2020

I've gotten this generating markdown in my local environment, but some shortcomings of glamour are making the output less than ideal; the primary issue is the inability to manually linebreak which I'd like for the flag usage lists. I'll explore using tables or blockquotes for that.

Either way I have to focus on other things today but I'll circle back to this.

@vilmibm
Copy link
Contributor

vilmibm commented Nov 16, 2020

I've pushed commits for having this output markdown. I had to make some trade-offs but I think it looks acceptable; most importantly, it should look ok on the manual website.

image

@vilmibm vilmibm requested review from mislav and samcoe November 16, 2020 23:40
@vilmibm vilmibm dismissed their stale review November 17, 2020 19:14

changes made, then i worked a lot on the PR

@vilmibm vilmibm requested a review from samcoe November 17, 2020 19:14
- the `<...>` characters from command usage line are now preserved by enclosing the entire usage synopsis in a code span
- hard breaks in flag usage lines are preserved by enclosing flag usage in a code block
- TTY detection and Markdown rendering are now delayed until the user explicitly requests `gh help reference`
- `gh help reference` output is now pager-enabled
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Great work everyone!

I've pushed some changes to simplify things and add PAGER support. This is how gh reference looks now:

Screen Shot 2020-11-17 at 20 57 36

I've avoided Markdown issues around <...> and line breaks by wrapping those sections in <code> spans or blocks. Particularly, FlagUsages() output should be rendered in a code block due to its output currently being vertically-aligned.

When stdout is not a terminal, the reference command outputs no color. Similarly, no Markdown rendering or terminal detection happens when initializing the reference command, since that would add to the overhead of executing any gh command. Instead, rendering and detecting terminal features now only happens if the reference output was actually requested.

@vilmibm @samcoe When rebasing my changes onto this branch, I've removed the Static/DynamicHelpTopic distinction in the cleanup. It didn't feel that right now we need to maintain that distinction, since each of the functions had precisely 1 caller. It was also relatively easy to implement this with our original NewHelpTopic() function without any modifications.

Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

I didn't think of nesting codes into h2s, i'm glad that works.

I had considered doing the pre approach for flags but was worried about over indentation; it looks fine though 👍

cmdutil.DisableAuthCheck(cmd)

// this needs to appear last:
referenceCmd.Long = referenceLong(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike this approach but don't see value in further back and forthing on this given that we only have two help topics


_ = io.StartPager()
defer io.StopPager()
fmt.Fprint(io.Out, md)
Copy link
Contributor

Choose a reason for hiding this comment

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

good thinking.

the environment help topic is also long and i assume future help topics will also be greater than one "page" (which seems to be the point of them) so we might want to consider always running the pager for help topics in the future

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.

"reference" help topic to list all commands and subcommands

6 participants