core/commands2: Added function to generate a 'commands' command for a root
Matt Bell committed
Nov 12, 2014 at 16:55 UTC
f797d1357933966ef82fc65557954414c88b5885
2 files changed
+21
-17
core/commands2/commands.go
+20
-16
@@ -11,23 +11,27 @@ type Command struct {
11
Subcommands []Command
12
}
13
14
-var commandsCmd = &cmds.Command{
15
- Description: "List all available commands.",
16
- Help: `Lists all available commands (and subcommands) and exits.
17
-`,
18
-
19
- Run: func(req cmds.Request) (interface{}, error) {
20
- root := outputCommand("ipfs", Root)
21
- return &root, nil
22
- },
23
- Marshallers: map[cmds.EncodingType]cmds.Marshaller{
24
- cmds.Text: func(res cmds.Response) ([]byte, error) {
25
- v := res.Output().(*Command)
26
- s := formatCommand("", v)
27
- return []byte(s), nil
14
+// CommandsCmd takes in a root command,
15
+// and returns a command that lists the subcommands in that root
16
+func CommandsCmd(root *cmds.Command) *cmds.Command {
17
+ return &cmds.Command{
18
+ Description: "List all available commands.",
19
+ Help: `Lists all available commands (and subcommands) and exits.
20
+ `,
21
+
22
+ Run: func(req cmds.Request) (interface{}, error) {
23
+ root := outputCommand("ipfs", root)
24
+ return &root, nil
25
+ },
26
+ Marshallers: map[cmds.EncodingType]cmds.Marshaller{
27
+ cmds.Text: func(res cmds.Response) ([]byte, error) {
28
+ v := res.Output().(*Command)
29
+ s := formatCommand("", v)
30
+ return []byte(s), nil
31
+ },
32
},
29
- },
30
- Type: &Command{},
33
+ Type: &Command{},
34
+ }
35
}
36
37
func outputCommand(name string, cmd *cmds.Command) Command {
core/commands2/root.go
+1
-1
@@ -52,7 +52,7 @@ Plumbing commands:
52
var rootSubcommands = map[string]*cmds.Command{
53
"cat": catCmd,
54
"ls": lsCmd,
55
- "commands": commandsCmd,
55
+ "commands": CommandsCmd(Root),
56
"name": nameCmd,
57
"add": addCmd,
58
"log": logCmd,