mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 18:05:32 +08:00
commands: Got rid of old helptext fields, use HelpText struct fields in helptext generator
This commit is contained in:

committed by
Juan Batiz-Benet

parent
e700b16576
commit
646920b0dd
@ -130,38 +130,31 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
|
|||||||
pathStr += " " + strings.Join(path, " ")
|
pathStr += " " + strings.Join(path, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: get the fields from the HelpText struct by default (when commands are ported to use it)
|
|
||||||
fields := helpFields{
|
fields := helpFields{
|
||||||
Indent: indentStr,
|
Indent: indentStr,
|
||||||
Path: pathStr,
|
Path: pathStr,
|
||||||
ArgUsage: usageText(cmd),
|
ArgUsage: usageText(cmd),
|
||||||
Tagline: cmd.Description,
|
Tagline: cmd.Helptext.Tagline,
|
||||||
Arguments: cmd.ArgumentHelp,
|
Arguments: cmd.Helptext.Arguments,
|
||||||
Options: cmd.OptionHelp,
|
Options: cmd.Helptext.Options,
|
||||||
Synopsis: cmd.Helptext.Synopsis,
|
Synopsis: cmd.Helptext.Synopsis,
|
||||||
Subcommands: cmd.SubcommandHelp,
|
Subcommands: cmd.Helptext.Subcommands,
|
||||||
Description: cmd.Help,
|
Description: cmd.Helptext.ShortDescription,
|
||||||
|
Usage: cmd.Helptext.Usage,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: don't do these checks, just use these fields by default (when commands get ported to it)
|
if len(cmd.Helptext.LongDescription) > 0 {
|
||||||
if len(cmd.Helptext.Tagline) > 0 {
|
fields.Description = cmd.Helptext.LongDescription
|
||||||
fields.Tagline = cmd.Helptext.Tagline
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.ShortDescription) > 0 {
|
|
||||||
fields.Description = cmd.Helptext.ShortDescription
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.Usage) > 0 {
|
|
||||||
fields.Usage = cmd.Helptext.Subcommands
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// autogen fields that are empty
|
// autogen fields that are empty
|
||||||
if len(cmd.ArgumentHelp) == 0 {
|
if len(fields.Arguments) == 0 {
|
||||||
fields.Arguments = strings.Join(argumentText(cmd), "\n")
|
fields.Arguments = strings.Join(argumentText(cmd), "\n")
|
||||||
}
|
}
|
||||||
if len(cmd.OptionHelp) == 0 {
|
if len(fields.Options) == 0 {
|
||||||
fields.Options = strings.Join(optionText(cmd), "\n")
|
fields.Options = strings.Join(optionText(cmd), "\n")
|
||||||
}
|
}
|
||||||
if len(cmd.SubcommandHelp) == 0 {
|
if len(fields.Subcommands) == 0 {
|
||||||
fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n")
|
fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,29 +188,10 @@ func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer
|
|||||||
Indent: indentStr,
|
Indent: indentStr,
|
||||||
Path: pathStr,
|
Path: pathStr,
|
||||||
ArgUsage: usageText(cmd),
|
ArgUsage: usageText(cmd),
|
||||||
Tagline: cmd.Description,
|
Tagline: cmd.Helptext.Tagline,
|
||||||
Synopsis: cmd.Helptext.Synopsis,
|
Synopsis: cmd.Helptext.Synopsis,
|
||||||
Description: cmd.Help,
|
Description: cmd.Helptext.ShortDescription,
|
||||||
}
|
Usage: cmd.Helptext.Usage,
|
||||||
|
|
||||||
// TODO: don't do these checks, just use these fields by default (when commands get ported to it)
|
|
||||||
if len(cmd.Helptext.Tagline) > 0 {
|
|
||||||
fields.Tagline = cmd.Helptext.Tagline
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.Arguments) > 0 {
|
|
||||||
fields.Arguments = cmd.Helptext.Arguments
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.Options) > 0 {
|
|
||||||
fields.Options = cmd.Helptext.Options
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.Subcommands) > 0 {
|
|
||||||
fields.Subcommands = cmd.Helptext.Subcommands
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.ShortDescription) > 0 {
|
|
||||||
fields.Description = cmd.Helptext.ShortDescription
|
|
||||||
}
|
|
||||||
if len(cmd.Helptext.Usage) > 0 {
|
|
||||||
fields.Usage = cmd.Helptext.Subcommands
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim the extra newlines (see TrimNewlines doc)
|
// trim the extra newlines (see TrimNewlines doc)
|
||||||
@ -311,11 +285,7 @@ func subcommandText(cmd *cmds.Command, rootName string, path []string) []string
|
|||||||
if len(usage) > 0 {
|
if len(usage) > 0 {
|
||||||
usage = " " + usage
|
usage = " " + usage
|
||||||
}
|
}
|
||||||
if len(sub.Helptext.Tagline) > 0 {
|
lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Helptext.Tagline)
|
||||||
lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Helptext.Tagline)
|
|
||||||
} else {
|
|
||||||
lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Description)
|
|
||||||
}
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +44,6 @@ type HelpText struct {
|
|||||||
// 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 {
|
||||||
// TODO: remove these fields after porting commands to HelpText struct
|
|
||||||
Description string
|
|
||||||
Help string
|
|
||||||
SubcommandHelp string
|
|
||||||
OptionHelp string
|
|
||||||
ArgumentHelp string
|
|
||||||
|
|
||||||
Options []Option
|
Options []Option
|
||||||
Arguments []Argument
|
Arguments []Argument
|
||||||
Run Function
|
Run Function
|
||||||
|
Reference in New Issue
Block a user