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

v2 feature: Use app.Description in templates #1286

Closed
3 tasks done
subpop opened this issue Jun 30, 2021 · 0 comments · Fixed by #1287
Closed
3 tasks done

v2 feature: Use app.Description in templates #1286

subpop opened this issue Jun 30, 2021 · 0 comments · Fixed by #1287
Labels
area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this

Comments

@subpop
Copy link
Contributor

subpop commented Jun 30, 2021

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this feature? Here's the Github guide about searching.

What problem does this solve?

I was adding a .Description value to my main application, and I was surprised to find the text is not included in the output during man-page and markdown generation. Instead, the templates put App.UsageText in a section titled DESCRIPTION. Was this deliberate? If so, what is the difference between App.UsageText and App.Description? I assumed App.Description should be printed in the DESCRIPTION section, while the App.UsageText value is printed in place of the generated Usage Text:

{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]

Solution description

I believe a diff similar to the following would enable both UsageText and Description output:

diff --git a/template.go b/template.go
index 69e040e..e0b8a6b 100644
--- a/template.go
+++ b/template.go
@@ -86,15 +86,19 @@ var MarkdownDocTemplate = `% {{ .App.Name }} {{ .SectionNum }}
 {{ if .SynopsisArgs }}
 ` + "```" + `
 {{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
-{{ end }}{{ if .App.UsageText }}
+{{ end }}{{ if .App.Description }}
 # DESCRIPTION
 
-{{ .App.UsageText }}
+{{ .App.Description }}
 {{ end }}
 **Usage**:
 
 ` + "```" + `
+{{ if .App.UsageText }}
+{{ .App.UsageText }}
+{{ else }}
 {{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
+{{ end }}
 ` + "```" + `
 {{ if .GlobalArgs }}
 # GLOBAL OPTIONS

Describe alternatives you've considered

I don't like putting my long-form description text in the UsageText field. Description has some nice formatting during console printing, and UsageText does not.

@subpop subpop added area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this labels Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant