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
feat(docs): add UsageText to docs output for markdown and man page generation #1171
Conversation
@rliebz and @lynncyrin any chance that this can get merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, and sorry for the delay here. Got a few comments for you, but overall this looks great!
docs.go
Outdated
usageText := "" | ||
if command.UsageText != "" { | ||
// Remove leading and trailing newlines | ||
preparedUsageText := strings.TrimSuffix(command.UsageText, "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to intentionally trim exactly up to one leading newline and one trailing newline? Or is the goal to trim all leading/trailing newlines?
For trimming all newlines from either side:
preparedUsageText := strings.Trim(command.UsageText, "\n")
For trimming all whitespace from either end:
preparedUsageText := strings.TrimSpace(command.UsageText)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preparedUsageText := strings.Trim(command.UsageText, "\n")
That is what I was looking for. Thank you for the suggestion! It was intended to remove all leading and trailing newlines.
docs.go
Outdated
// Format multi-line string as a code block | ||
usageText = fmt.Sprintf("```\n%s\n```\n", preparedUsageText) | ||
} else { | ||
// Style a single line as a note |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious—why use a block-quote for a one-line usage text? I'm not sure I understand why the style would be different for a one-liner versus a multi-liner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a styling opinion more than anything. The use case I was considering was a very long one-line comment. Say 200+ characters in length. Within markdown there is no styling for the wrapping rules on a pre-formatted text block. This is particularly pronounced on Github where the CSS rules for a text block are quite narrow. Take the case below as an example.
This will retrieve the stored secrets within AWS Secrets Manager and map them via the secrets.yml file used by the 'summon' CLI tool to generate the current state of Environment Variables for a given stage.
versus
This will retrieve the stored secrets within AWS Secrets Manager and map them via the secrets.yml file used by the 'summon' CLI tool to generate the current state of Environment Variables for a given stage.
With a >
note syntax, the markdown render will wrap the text accordingly. With the pre-formatted text block, it scrolls off screen making it difficult to read.
I dabbled with using >
across many lines, but there were quite a few edge cases that made predicting the desired markdown format unruly.
Thank you very much for the feedback and suggestions. I will get to updating tests and responding to the feedback. I had hoped to get to it last week, but life and work kept pulling me away. Sorry for the delay! |
8f6a854
to
364d9c3
Compare
@rliebz Rebased with current |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
364d9c3
to
8ea90fb
Compare
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
I put together an extension of sorts that accomplishes this feature (and more). https://github.com/clok/cdocs I would really like to put these features in the mainline as I feel they are useful for all I have updated the code, fixed the linting errors. Waiting for a review from maintainers. Thanks! |
any chance this can be reconsidered? It seems a pain to have to do external markdown generation to accomplish the same meanwhile, even if there's an add-on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry again for the delays here! This looks great, thanks for the contribution!
Awesome! Happy to contribute. |
I think this may have drifted the
|
the above was from this.. Usage: "Download and install a <version> of Envoy",
ArgsUsage: "<version>",
UsageText: fmt.Sprintf(`The '<version>' is from the "versions" command.
The Envoy <version> will be installed into $GETENVOY_HOME/versions/<version>
Example:
$ getenvoy install %s`, version.LastKnownEnvoy), |
@codefromthecrypt Would you mind opening an issue for that? If there's a bug in the behavior here, it's easier to keep track of if we have an issue with the expected behavior and steps to reproduce. |
Thanks! |
Nice catch on the regression. I'm sorry about that unintended change. I'll take a look at the issue and if it hasn't been addressed yet, I'll work on a fix for it. |
Got a PR up (#1279) to address the issue raised by @codefromthecrypt |
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
As a tools developer, I find the
UsageText
field to be useful in providing details on what a command does and how to use it. A good example is with gwsmFor example, the command
gwsm diff
has as detailed description that helps the user know how to use the command.I would like for the docs generation (
ToMarkdown
andToMan
) to include this help text in the docs.See the before and after here:
Which issue(s) this PR fixes:
(REQUIRED)
N/A - New feature
Testing
Updated a local copy of an existing tool (gwsm) with the delta applied and generated before/after docs.
See the before and after here:
Release Notes
(REQUIRED)