Skip to content

Adding Help Text To Commands - #568

Closed
WillHipschman wants to merge 4 commits into
git-lfs:masterfrom
WillHipschman:HelpText
Closed

WillHipschman wants to merge 4 commits into
git-lfs:masterfrom
WillHipschman:HelpText

Conversation

@WillHipschman

Copy link
Copy Markdown

Currently using git lfs help checkout will not display anything other than the base help text of the Cobra command.

This change parses the .ronn man files in /docs/ and writes them to go variables as part of script/bootstrap using go generators. When making a man change (adding a new command/man file or modifying a current one) the help text can be regenerated by running 'go generate' from the git-lfs root or by running the bootstrap script.

William Hipschman added 4 commits August 4, 2015 18:08
1.  Adds a generator declaration to convert .ronn documentation files into strings in help-text.go.
    Each time a .ronn file is changed the help text to should be re-generated by running 'go generate'
    before being built.

2.  Adds a long description to each command to allow Cobra to pick up help text.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Go doesn't really have a way to reflect over variables on a class, so I settled for a static map. If anyone has better ideas on how to map the man file names to variable names I'm all ears.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could just be generated along with the rest of the data. It wouldn't really bother me if it lived at the bottom of help-text.go. I think it's too easy to miss adding something to this list. What it's really testing is that the generator has run before building, and if something is missed then the test doesn't have much value.

@rubyist

rubyist commented Aug 6, 2015

Copy link
Copy Markdown
Contributor

It looks like a couple .exe files were added that probably shouldn't have been.

Comment thread docs/include-help-text.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should go along with the other stuff under script/. That's our general convention so far, and things under docs/ do not get run through the formatter, which can lead to formatting and tab issues on different machines. There are several lines that don't have correct tabbing and there should be a space after import.

@rubyist

rubyist commented Aug 6, 2015

Copy link
Copy Markdown
Contributor

The help-text_test.go file has several formatting issues, can you run that through goimports (script/fmt should be doing this) and clean that up?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Go keywords tend to be in camelCase. Also, I think the git_lfs prefix here is redundant. I think you could name these after the subcommand: checkoutHelp, cleanHelp, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍, and along with this, I think i'd rather see _ in the file names than -.

@rubyist

rubyist commented Aug 6, 2015

Copy link
Copy Markdown
Contributor

Higher level feedback:

How does everyone feel about it displaying raw markdown to the terminal? I don't ❤️ it, but if it doesn't bother anyone else then I won't oppose it. I wouldn't want to pull in a markdown parser and display it formatted or anything, just maybe strip the markdown out.

I'm also thinking that this approach differs a little from git. I'm just spitballing here, but I'll throw this out for consideration/discussion.

When you do git help checkout, for example, it displays the formatted man page in your configured pager/browser/what have you. While git help lfs does work, it's unfortunate that git won't dig into sub commands and give us git help lfs checkout. However, it does work to do git help git-lfs-checkout. The cobra.Command setup allows us to provide our own HelpFunc, so it's possible that git lfs help checkout can just shell out to git help git-lfs-checkout rendering the way git typically would.

The caveat to that is it only works if the Git LFS man pages have been installed, but git does give a correct exit code if it's not found and we could fallback to this generated output, so we'd probably need to keep both (though ideally, man pages are installed).

@technoweenie

Copy link
Copy Markdown
Contributor

How does everyone feel about it displaying raw markdown to the terminal?

Markdown is designed to look good in plain text, unless you're doing some weird stuff like extra html tags or tables. So I'm ok with it. But there are some tags, like <br>, that need to be stripped out.

I think I'd prefer git ignoring commands/help-text.go, and relying on script/bootstrap to generate that each time.

The cobra.Command setup allows us to provide our own HelpFunc, so it's possible that git lfs help checkout can just shell out to git help git-lfs-checkout rendering the way git typically would.

I like this idea, actually. The markdown ronn files are converted to proper man pages, which git already knows how to display. It'd also keep us from storing the help text twice (in ronn files, and again in the go code).

Now, since we don't have a reliable way to install man pages cross platform yet, I think this PR is a good workaround. I think the commands/help-text.go file should be git ignored. The various scripts should all bootstrap before building/testing/running the code, so this should be fine.

Also, do we even need these git_lfs_checkout_HelpText variables? It could be in a big map that gets generated:

var help = map[string]string {
  "checkout": `git-lfs-checkout(1) -- Update working copy with file content if available............`,
  "clean": "...........",

It's still very easy to set this to the Long property on *cobra.Command objects. It's also easy to see what commands are documented by checking or iterating through the map.

@sinbad

sinbad commented Aug 14, 2015

Copy link
Copy Markdown
Contributor

First: I love that this is on the radar to fix. 👍

The caveat to that is it only works if the Git LFS man pages have been installed

Just incase it hasn't come up yet, were you aware that the default behaviour in Windows for something like git checkout --help is that it launches the browser & displays the HTML version of the man page? The msys git install doesn't seem to include man so this is the alternative, I'm not sure what triggers it all & whether that will work for us too. Just a thought since we're generating HTML from ronn too.

@technoweenie

Copy link
Copy Markdown
Contributor

Closing this. This was a great idea, but @sinbad's approach with go generate in #665 keeps us from maintaining the help text in multiple places. Those ronn files are now a single source of truth 🤘

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.

4 participants