Commit 503bd672 authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

commands: Allow overriding helptext sections with hand-written strings

parent f6281e5a
......@@ -36,18 +36,36 @@ func HelpText(rootName string, root *cmds.Command, path []string) (string, error
}
if cmd.Arguments != nil {
lines := indent(argumentText(cmd), " ")
s += fmt.Sprintf("Arguments:\n%v\n\n", strings.Join(lines, "\n"))
if len(cmd.ArgumentHelp) > 0 {
s += cmd.ArgumentHelp
} else {
section := strings.Join(indent(argumentText(cmd), " "), "\n")
s += fmt.Sprintf("Arguments:\n%v", section)
}
s += "\n\n"
}
if cmd.Subcommands != nil {
lines := indent(subcommandText(cmd, rootName, path), " ")
s += fmt.Sprintf("Subcommands:\n%v\n\n", strings.Join(lines, "\n"))
if len(cmd.SubcommandHelp) > 0 {
s += cmd.SubcommandHelp
} else {
section := strings.Join(indent(subcommandText(cmd, rootName, path), " "), "\n")
s += fmt.Sprintf("Subcommands:\n%v", section)
}
s += "\n\n"
}
if cmd.Options != nil {
lines := indent(optionText(cmd), " ")
s += fmt.Sprintf("Options:\n%v\n\n", strings.Join(lines, "\n"))
if len(cmd.OptionHelp) > 0 {
s += cmd.OptionHelp
} else {
section := strings.Join(indent(optionText(cmd), " "), "\n")
s += fmt.Sprintf("Options:\n%v", section)
}
s += "\n\n"
}
return s, nil
......
......@@ -28,8 +28,13 @@ type Marshaller func(Response) ([]byte, error)
// Command is a runnable command, with input arguments and options (flags).
// It can also have Subcommands, to group units of work into sets.
type Command struct {
Description string
Help string
// MAYBE_TODO: move all the text fields into a struct
// MAYBE_TODO: move these out of command and put them somewhere in commands/cli
Description string
Help string
SubcommandHelp string
OptionHelp string
ArgumentHelp string
Options []Option
Arguments []Argument
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment