Skip to content

Commit 1bb6a63

Browse files
committedOct 17, 2015
ipfs commands --flags: display short & long flag
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
1 parent 3e2016d commit 1bb6a63

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎core/commands/commands.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"bytes"
1212
"io"
1313
"sort"
14+
"strings"
1415

1516
cmds "github.com/ipfs/go-ipfs/commands"
1617
)
@@ -23,7 +24,7 @@ type Command struct {
2324
}
2425

2526
const (
26-
flagsOptionName = "flags"
27+
flagsOptionName = "flags"
2728
)
2829

2930
// CommandsCmd takes in a root command,
@@ -38,7 +39,7 @@ func CommandsCmd(root *cmds.Command) *cmds.Command {
3839
cmds.BoolOption(flagsOptionName, "f", "Show command flags"),
3940
},
4041
Run: func(req cmds.Request, res cmds.Response) {
41-
showOptions, _, _ := req.Option(flagsOptionName).Bool();
42+
showOptions, _, _ := req.Option(flagsOptionName).Bool()
4243
rootCmd := cmd2outputCmd("ipfs", root, showOptions)
4344
res.SetOutput(&rootCmd)
4445
},
@@ -82,13 +83,17 @@ func cmdPathStrings(cmd *Command) []string {
8283
cmds = append(cmds, newPrefix)
8384
if prefix != "" && cmd.ShowOptions {
8485
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)
9095
}
91-
cmds = append(cmds, newPrefix+" "+optName)
96+
cmds = append(cmds, strings.Join(cmdOpts, " / "))
9297
}
9398
}
9499
for _, sub := range cmd.Subcommands {

0 commit comments

Comments
 (0)
Please sign in to comment.