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

Implement SEE ALSO section in help output #472

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ COMMANDS
vcl Manipulate Fastly service version VCL
version Display version information for the Fastly CLI
whoami Get information about the currently authenticated account

SEE ALSO
https://developer.fastly.com/reference/cli/
`) + "\n\n"

var helpService = strings.TrimSpace(`
Expand Down Expand Up @@ -265,6 +268,9 @@ SUBCOMMANDS
-n, --name=NAME Service name
--comment=COMMENT Human-readable comment

SEE ALSO
https://developer.fastly.com/reference/cli/service/

`) + "\n\n"

var fullFatHelpDefault = strings.TrimSpace(`
Expand Down Expand Up @@ -4254,6 +4260,9 @@ COMMANDS
Get information about the currently authenticated account


SEE ALSO
https://developer.fastly.com/reference/cli/

For help on a specific command, try e.g.

fastly help configure
Expand Down
15 changes: 14 additions & 1 deletion pkg/app/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ var UsageTemplateFuncs = template.FuncMap{
"Bold": func(s string) string {
return text.Bold(s)
},
"SeeAlso": func(cm *kingpin.CmdModel) string {
cmd := cm.FullCommand()
url := "https://developer.fastly.com/reference/cli/"
var trail string
if len(cmd) > 0 {
trail = "/"
}
return fmt.Sprintf(" %s%s%s", url, strings.ReplaceAll(cmd, " ", "/"), trail)
},
}

// CompactUsageTemplate is the default usage template, rendered when users type
Expand Down Expand Up @@ -214,6 +223,8 @@ var CompactUsageTemplate = `{{define "FormatCommand" -}}
{{T "COMMANDS"|Bold}}
{{.App.Commands|CommandsToTwoColumns|FormatTwoColumns}}
{{end -}}
{{T "SEE ALSO"|Bold}}
{{.Context.SelectedCommand|SeeAlso}}
`

// VerboseUsageTemplate is the full-fat usage template, rendered when users type
Expand Down Expand Up @@ -259,6 +270,8 @@ const VerboseUsageTemplate = `{{define "FormatCommands" -}}
{{T "COMMANDS"|Bold -}}
{{template "FormatCommands" .App}}
{{end -}}
{{T "SEE ALSO"|Bold}}
{{.Context.SelectedCommand|SeeAlso}}
`

// displayHelp returns a function that prints the help output for a command or
Expand Down Expand Up @@ -430,7 +443,7 @@ func processCommandInput(
// distinguish `fastly help` from e.g. `fastly help configure` than this
// check.
if len(opts.Args) > 0 && opts.Args[len(opts.Args)-1] == "help" {
fmt.Fprintln(&buf, "For help on a specific command, try e.g.")
fmt.Fprintln(&buf, "\nFor help on a specific command, try e.g.")
fmt.Fprintln(&buf, "")
fmt.Fprintln(&buf, "\tfastly help configure")
fmt.Fprintln(&buf, "\tfastly configure --help")
Expand Down