From fd8b1930af82effe5f03097f1acdd89ac9ae893a Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 12 Nov 2014 16:46:51 -0800 Subject: [PATCH] cmd/ipfs2: Copy subcommands from core/commands2 root into cmd/ipfs2 root --- cmd/ipfs2/ipfs.go | 24 +++++++++++++++++++----- cmd/ipfs2/main.go | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/ipfs2/ipfs.go b/cmd/ipfs2/ipfs.go index ef359e370..7e3b0e873 100644 --- a/cmd/ipfs2/ipfs.go +++ b/cmd/ipfs2/ipfs.go @@ -8,9 +8,23 @@ import ( var Root = &cmds.Command{ Options: commands.Root.Options, Help: commands.Root.Help, - Subcommands: map[string]*cmds.Command{ - "daemon": daemonCmd, // TODO name - "init": initCmd, // TODO name - "tour": cmdTour, - }, +} + +var rootSubcommands = map[string]*cmds.Command{ + "daemon": daemonCmd, // TODO name + "init": initCmd, // TODO name + "tour": cmdTour, +} + +func init() { + // setting here instead of in literal to prevent initialization loop + // (some commands make references to Root) + Root.Subcommands = rootSubcommands + + // copy all subcommands from commands.Root into this root (if they aren't already present) + for k, v := range commands.Root.Subcommands { + if _, found := Root.Subcommands[k]; !found { + Root.Subcommands[k] = v + } + } } diff --git a/cmd/ipfs2/main.go b/cmd/ipfs2/main.go index ff12ff45e..ded62b2dc 100644 --- a/cmd/ipfs2/main.go +++ b/cmd/ipfs2/main.go @@ -94,7 +94,7 @@ func run() error { } func createRequest(args []string) (cmds.Request, *cmds.Command, error) { - req, root, cmd, path, err := cmdsCli.Parse(args, Root, commands.Root) + req, root, cmd, path, err := cmdsCli.Parse(args, Root) // handle parse error (which means the commandline input was wrong, // e.g. incorrect number of args, or nonexistent subcommand)