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
Add word-wrap support, with wrap length provided by the user #1119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,16 @@ package cli | |
// cli.go uses text/template to render templates. You can | ||
// render custom help text by setting this variable. | ||
var AppHelpTemplate = `NAME: | ||
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}} | ||
{{$v := offset .Name 6}}{{wrap .Name 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're wrapping most of the fields in the template, but not all of the fields. This PR also omits wrapping for command help and sub-command help. Is there a reason NOT to expand wrapping to all sections of all templates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly because I don't know all the variations that need to be tested. I suspect there will be some fields that aren't worth trying to wrap because they're only a problem in unusual cases, but command and sub-command help are worth supporting. I will try to expand this a bit. |
||
|
||
USAGE: | ||
{{if .UsageText}}{{.UsageText | nindent 3 | trim}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} | ||
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} | ||
|
||
VERSION: | ||
{{.Version}}{{end}}{{end}}{{if .Description}} | ||
|
||
DESCRIPTION: | ||
{{.Description | nindent 3 | trim}}{{end}}{{if len .Authors}} | ||
{{wrap .Description 3}}{{end}}{{if len .Authors}} | ||
|
||
AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: | ||
{{range $index, $author := .Authors}}{{if $index}} | ||
|
@@ -31,26 +31,26 @@ GLOBAL OPTIONS:{{range .VisibleFlagCategories}} | |
|
||
GLOBAL OPTIONS: | ||
{{range $index, $option := .VisibleFlags}}{{if $index}} | ||
{{end}}{{$option}}{{end}}{{end}}{{end}}{{if .Copyright}} | ||
{{end}}{{wrap $option.String 6}}{{end}}{{end}}{{end}}{{if .Copyright}} | ||
|
||
COPYRIGHT: | ||
{{.Copyright}}{{end}} | ||
{{wrap .Copyright 3}}{{end}} | ||
` | ||
|
||
// CommandHelpTemplate is the text template for the command help topic. | ||
// cli.go uses text/template to render templates. You can | ||
// render custom help text by setting this variable. | ||
var CommandHelpTemplate = `NAME: | ||
{{.HelpName}} - {{.Usage}} | ||
{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}} | ||
|
||
USAGE: | ||
{{if .UsageText}}{{.UsageText | nindent 3 | trim}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} | ||
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} | ||
|
||
CATEGORY: | ||
{{.Category}}{{end}}{{if .Description}} | ||
|
||
DESCRIPTION: | ||
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleFlagCategories}} | ||
{{wrap .Description 3}}{{end}}{{if .VisibleFlagCategories}} | ||
|
||
OPTIONS:{{range .VisibleFlagCategories}} | ||
{{if .Name}}{{.Name}} | ||
|
@@ -69,10 +69,10 @@ var SubcommandHelpTemplate = `NAME: | |
{{.HelpName}} - {{.Usage}} | ||
|
||
USAGE: | ||
{{if .UsageText}}{{.UsageText | nindent 3 | trim}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}} | ||
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}} | ||
|
||
DESCRIPTION: | ||
{{.Description | nindent 3 | trim}}{{end}} | ||
{{wrap .Description 3}}{{end}} | ||
|
||
COMMANDS:{{range .VisibleCategories}}{{if .Name}} | ||
{{.Name}}:{{range .VisibleCommands}} | ||
|
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 think it is better to define a type for this function signature.
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 not quite sure what you mean- are you suggesting that we export a
WrapAtFunc
type alias, and then only usecustomFuncs["wrapAt"]
if it is created as aWrapAtFunc
explicitly?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.
Gentle ping on this :)
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.
Yes correct
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.
This requires some boilerplate for the caller, but I'm not sure how it makes things better. How does this help? I couldn't find any examples of this pattern in a quick web search, but I'm not sure what to call this so maybe I'm missing something obvious.
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.
fwiw I'm happy to defer resolution of this to a later PR, so I'm going to move forward with merging the current work 👍🏼