core/commands2: Format 'commands' to match original output (re: #317)
Matt Bell committed
Nov 12, 2014 at 16:45 UTC
53e875e5fc15f9d08fba2a65a3b155976ea196eb
1 file changed
+7
-9
core/commands2/commands.go
+7
-9
@@ -2,7 +2,6 @@ package commands
2
3
import (
4
"fmt"
5
- "strings"
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
)
@@ -24,7 +23,7 @@ var commandsCmd = &cmds.Command{
23
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
24
cmds.Text: func(res cmds.Response) ([]byte, error) {
25
v := res.Output().(*Command)
27
- s := formatCommand(v, 0)
26
+ s := formatCommand("", v)
27
return []byte(s), nil
28
},
29
},
@@ -46,16 +45,15 @@ func outputCommand(name string, cmd *cmds.Command) Command {
45
return output
46
}
47
49
-func formatCommand(cmd *Command, depth int) string {
50
- var s string
51
-
52
- if depth > 0 {
53
- indent := strings.Repeat(" ", depth-1)
54
- s = fmt.Sprintf("%s%s\n", indent, cmd.Name)
48
+func formatCommand(prefix string, cmd *Command) string {
49
+ if len(prefix) > 0 {
50
+ prefix += " "
51
}
52
+ s := fmt.Sprintf("%s%s\n", prefix, cmd.Name)
53
54
+ prefix += cmd.Name
55
for _, sub := range cmd.Subcommands {
58
- s += formatCommand(&sub, depth+1)
56
+ s += formatCommand(prefix, &sub)
57
}
58
59
return s