From 63452ae356b7c05d830daa60f6aa3b767ef703fe Mon Sep 17 00:00:00 2001 From: yingzhuo Date: Tue, 29 Oct 2019 13:49:16 +0800 Subject: [PATCH] add see also for sub command --- command.go | 2 ++ help.go | 4 +++- help_test.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 415ec23..ce1e0d5 100644 --- a/command.go +++ b/command.go @@ -17,6 +17,8 @@ type Command struct { Description string // Examples of the program Examples string + // SeeAlso of the program + SeeAlso string // List of flags to parse Flags []*Flag diff --git a/help.go b/help.go index e29bab7..f1666e4 100644 --- a/help.go +++ b/help.go @@ -44,7 +44,7 @@ COMMANDS: EXAMPLES: {{- range .ExampleLines}} {{.}} -{{- end}}{{end}}{{if .SeeAlsoLines }} +{{- end}}{{end}}{{if .SeeAlsoLines}} SEE ALSO: {{- range .SeeAlsoLines}} @@ -94,6 +94,7 @@ func newCommandHelpContext(name string, cmd *Command, app *App) *HelpContext { UsageText: cmd.UsageText, Description: cmd.Description, Examples: cmd.Examples, + SeeAlso: cmd.SeeAlso, Flags: cmd.Flags, Commands: cmd.Commands, } @@ -180,6 +181,7 @@ func (c *HelpContext) ExampleLines() []string { return examples } +// SeeAlsoLines splits line for see also func (c *HelpContext) SeeAlsoLines() []string { c.SeeAlso = strings.TrimSpace(c.SeeAlso) if len(c.SeeAlso) == 0 { diff --git a/help_test.go b/help_test.go index 1359552..f78a96f 100644 --- a/help_test.go +++ b/help_test.go @@ -53,6 +53,7 @@ func TestHelpShowHelp(t *testing.T) { IsBool: true, }, }, + SeeAlso: "https://github.com/subchen/go-cli#build\nhttps://github.com/subchen/go-cli#build2", }, { Name: "release",