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 {
|
if cmd.Arguments != nil {
|
||||||
lines := indent(argumentText(cmd), " ")
|
if len(cmd.ArgumentHelp) > 0 {
|
||||||
s += fmt.Sprintf("Arguments:\n%v\n\n", strings.Join(lines, "\n"))
|
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 {
|
if cmd.Subcommands != nil {
|
||||||
lines := indent(subcommandText(cmd, rootName, path), " ")
|
if len(cmd.SubcommandHelp) > 0 {
|
||||||
s += fmt.Sprintf("Subcommands:\n%v\n\n", strings.Join(lines, "\n"))
|
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 {
|
if cmd.Options != nil {
|
||||||
lines := indent(optionText(cmd), " ")
|
if len(cmd.OptionHelp) > 0 {
|
||||||
s += fmt.Sprintf("Options:\n%v\n\n", strings.Join(lines, "\n"))
|
s += cmd.OptionHelp
|
||||||
|
} else {
|
||||||
|
section := strings.Join(indent(optionText(cmd), " "), "\n")
|
||||||
|
s += fmt.Sprintf("Options:\n%v", section)
|
||||||
|
}
|
||||||
|
|
||||||
|
s += "\n\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -28,8 +28,13 @@ type Marshaller func(Response) ([]byte, error)
|
|||||||
// Command is a runnable command, with input arguments and options (flags).
|
// Command is a runnable command, with input arguments and options (flags).
|
||||||
// It can also have Subcommands, to group units of work into sets.
|
// It can also have Subcommands, to group units of work into sets.
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Description string
|
// MAYBE_TODO: move all the text fields into a struct
|
||||||
Help string
|
// 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
|
Options []Option
|
||||||
Arguments []Argument
|
Arguments []Argument
|
||||||
|
Reference in New Issue
Block a user