1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 03:19:47 +08:00

Show flags in ipfs commands

License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
rht
2015-10-17 08:52:58 +07:00
parent 4de5eaad5f
commit 4da824c954

View File

@ -18,6 +18,7 @@ import (
type Command struct {
Name string
Subcommands []Command
Options []cmds.Option
}
// CommandsCmd takes in a root command,
@ -51,6 +52,7 @@ func cmd2outputCmd(name string, cmd *cmds.Command) Command {
output := Command{
Name: name,
Subcommands: make([]Command, len(cmd.Subcommands)),
Options: cmd.Options,
}
i := 0
@ -67,9 +69,21 @@ func cmdPathStrings(cmd *Command) []string {
var recurse func(prefix string, cmd *Command)
recurse = func(prefix string, cmd *Command) {
cmds = append(cmds, prefix+cmd.Name)
newPrefix := prefix + cmd.Name
cmds = append(cmds, newPrefix)
if prefix != "" {
for _, option := range cmd.Options {
optName := option.Names()[0]
if len(optName) == 1 {
optName = "-" + optName
} else {
optName = "--" + optName
}
cmds = append(cmds, newPrefix+" "+optName)
}
}
for _, sub := range cmd.Subcommands {
recurse(prefix+cmd.Name+" ", &sub)
recurse(newPrefix+" ", &sub)
}
}