@cryptotaxi247 / kubo / commits / 1bb6a63b1

`ipfs commands --flags`: display short & long flag

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Oct 17, 2015 at 16:45 UTC 1bb6a63b1199611dc895099651f3832fc4276dd4
1 file changed +13 -8
core/commands/commands.go
+13 -8
@@ -11,6 +11,7 @@ import (
11 "bytes"
12 "io"
13 "sort"
14 + "strings"
15
16 cmds "github.com/ipfs/go-ipfs/commands"
17 )
@@ -23,7 +24,7 @@ type Command struct {
24 }
25
26 const (
26 - flagsOptionName = "flags"
27 + flagsOptionName = "flags"
28 )
29
30 // CommandsCmd takes in a root command,
@@ -38,7 +39,7 @@ func CommandsCmd(root *cmds.Command) *cmds.Command {
39 cmds.BoolOption(flagsOptionName, "f", "Show command flags"),
40 },
41 Run: func(req cmds.Request, res cmds.Response) {
41 - showOptions, _, _ := req.Option(flagsOptionName).Bool();
42 + showOptions, _, _ := req.Option(flagsOptionName).Bool()
43 rootCmd := cmd2outputCmd("ipfs", root, showOptions)
44 res.SetOutput(&rootCmd)
45 },
@@ -82,13 +83,17 @@ func cmdPathStrings(cmd *Command) []string {
83 cmds = append(cmds, newPrefix)
84 if prefix != "" && cmd.ShowOptions {
85 for _, option := range cmd.Options {
85 - optName := option.Names()[0]
86 - if len(optName) == 1 {
87 - optName = "-" + optName
88 - } else {
89 - optName = "--" + optName
86 + names := option.Names()
87 + var cmdOpts []string
88 + for _, flag := range names {
89 + if len(flag) == 1 {
90 + flag = "-" + flag
91 + } else {
92 + flag = "--" + flag
93 + }
94 + cmdOpts = append(cmdOpts, newPrefix+" "+flag)
95 }
91 - cmds = append(cmds, newPrefix+" "+optName)
96 + cmds = append(cmds, strings.Join(cmdOpts, " / "))
97 }
98 }
99 for _, sub := range cmd.Subcommands {