cmd/ipfs2: Copy subcommands from core/commands2 root into cmd/ipfs2 root
Matt Bell committed
Nov 12, 2014 at 16:46 UTC
fd8b1930af82effe5f03097f1acdd89ac9ae893a
2 files changed
+20
-6
cmd/ipfs2/ipfs.go
+19
-5
@@ -8,9 +8,23 @@ import (
8
var Root = &cmds.Command{
9
Options: commands.Root.Options,
10
Help: commands.Root.Help,
11
- Subcommands: map[string]*cmds.Command{
12
- "daemon": daemonCmd, // TODO name
13
- "init": initCmd, // TODO name
14
- "tour": cmdTour,
15
- },
11
+}
12
+
13
+var rootSubcommands = map[string]*cmds.Command{
14
+ "daemon": daemonCmd, // TODO name
15
+ "init": initCmd, // TODO name
16
+ "tour": cmdTour,
17
+}
18
+
19
+func init() {
20
+ // setting here instead of in literal to prevent initialization loop
21
+ // (some commands make references to Root)
22
+ Root.Subcommands = rootSubcommands
23
+
24
+ // copy all subcommands from commands.Root into this root (if they aren't already present)
25
+ for k, v := range commands.Root.Subcommands {
26
+ if _, found := Root.Subcommands[k]; !found {
27
+ Root.Subcommands[k] = v
28
+ }
29
+ }
30
}
cmd/ipfs2/main.go
+1
-1
@@ -94,7 +94,7 @@ func run() error {
94
}
95
96
func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
97
- req, root, cmd, path, err := cmdsCli.Parse(args, Root, commands.Root)
97
+ req, root, cmd, path, err := cmdsCli.Parse(args, Root)
98
99
// handle parse error (which means the commandline input was wrong,
100
// e.g. incorrect number of args, or nonexistent subcommand)