mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 18:05:32 +08:00
commands: Allow overriding helptext sections with hand-written strings
This commit is contained in:

committed by
Juan Batiz-Benet

parent
6869ca44fa
commit
7666f8880c
@ -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 {
|
||||
// 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
|
||||
|
Reference in New Issue
Block a user