From bb8d4ebd6ba6e2004c3b03512dc57ff6c5d9677a Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Thu, 13 Nov 2014 03:42:55 -0800 Subject: [PATCH] cmds2: cmdDetailsMap --- cmd/ipfs2/ipfs.go | 32 ++++++++++++++++++++++++++++---- cmd/ipfs2/tour.go | 2 +- core/commands2/bootstrap.go | 6 +++--- core/commands2/diag.go | 2 +- core/commands2/log.go | 2 +- core/commands2/root.go | 13 ++++++++----- core/commands2/update.go | 2 +- core/commands2/version.go | 2 +- 8 files changed, 44 insertions(+), 17 deletions(-) diff --git a/cmd/ipfs2/ipfs.go b/cmd/ipfs2/ipfs.go index a149e7eb1..e12d60376 100644 --- a/cmd/ipfs2/ipfs.go +++ b/cmd/ipfs2/ipfs.go @@ -13,13 +13,16 @@ var Root = &cmds.Command{ Helptext: commands.Root.Helptext, } +// commandsClientCmd is the "ipfs commands" command for local cli +var commandsClientCmd = commands.CommandsCmd(Root) + // Commands in localCommands should always be run locally (even if daemon is running). // They can override subcommands in commands.Root by defining a subcommand with the same name. var localCommands = map[string]*cmds.Command{ - "daemon": daemonCmd, // TODO name - "init": initCmd, // TODO name - "tour": cmdTour, - "commands": commands.CommandsCmd(Root), + "daemon": daemonCmd, + "init": initCmd, + "tour": tourCmd, + "commands": commandsClientCmd, } var localMap = make(map[*cmds.Command]bool) @@ -45,3 +48,24 @@ func isLocal(cmd *cmds.Command) bool { _, found := localMap[cmd] return found } + +type cmdDetails struct { + cannotRunOnClient bool + cannotRunOnDaemon bool + doesNotUseRepo bool +} + +// "What is this madness!?" you ask. Our commands have the unfortunate problem of +// not being able to run on all the same contexts. This map describes these +// properties so that other code can make decisions about whether to invoke a +// command or return an error to the user. +var cmdDetailsMap = map[*cmds.Command]cmdDetails{ + initCmd: cmdDetails{cannotRunOnDaemon: true, doesNotUseRepo: true}, + daemonCmd: cmdDetails{cannotRunOnDaemon: true}, + commandsClientCmd: cmdDetails{doesNotUseRepo: true}, + commands.CommandsDaemonCmd: cmdDetails{doesNotUseRepo: true}, + commands.DiagCmd: cmdDetails{cannotRunOnClient: true}, + commands.VersionCmd: cmdDetails{doesNotUseRepo: true}, + commands.UpdateCmd: cmdDetails{cannotRunOnDaemon: true}, + commands.LogCmd: cmdDetails{cannotRunOnClient: true}, +} diff --git a/cmd/ipfs2/tour.go b/cmd/ipfs2/tour.go index da0d6f422..6baa4c5c3 100644 --- a/cmd/ipfs2/tour.go +++ b/cmd/ipfs2/tour.go @@ -13,7 +13,7 @@ import ( tour "github.com/jbenet/go-ipfs/tour" ) -var cmdTour = &cmds.Command{ +var tourCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "An introduction to IPFS", ShortDescription: ` diff --git a/core/commands2/bootstrap.go b/core/commands2/bootstrap.go index 3217cb66e..825310c8e 100644 --- a/core/commands2/bootstrap.go +++ b/core/commands2/bootstrap.go @@ -37,9 +37,9 @@ Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'. Type: bootstrapListCmd.Type, Subcommands: map[string]*cmds.Command{ - "list": bootstrapListCmd, - "add": bootstrapAddCmd, - "rm": bootstrapRemoveCmd, + "list": bootstrapListCmd, + "add": bootstrapAddCmd, + "rm": bootstrapRemoveCmd, }, } diff --git a/core/commands2/diag.go b/core/commands2/diag.go index 8a68a02ba..764ac3f8b 100644 --- a/core/commands2/diag.go +++ b/core/commands2/diag.go @@ -28,7 +28,7 @@ type DiagnosticOutput struct { Peers []DiagnosticPeer } -var diagCmd = &cmds.Command{ +var DiagCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Generates diagnostic reports", }, diff --git a/core/commands2/log.go b/core/commands2/log.go index ace008d9f..1c821dbdc 100644 --- a/core/commands2/log.go +++ b/core/commands2/log.go @@ -13,7 +13,7 @@ import ( // we convert it at this step. var logAllKeyword = "all" -var logCmd = &cmds.Command{ +var LogCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Change the logging level", ShortDescription: ` diff --git a/core/commands2/root.go b/core/commands2/root.go index 798bcd7cf..bcf58f565 100644 --- a/core/commands2/root.go +++ b/core/commands2/root.go @@ -51,21 +51,24 @@ Plumbing commands: }, } +// commandsDaemonCmd is the "ipfs commands" command for daemon +var CommandsDaemonCmd = CommandsCmd(Root) + var rootSubcommands = map[string]*cmds.Command{ "cat": catCmd, "ls": lsCmd, - "commands": CommandsCmd(Root), + "commands": CommandsDaemonCmd, "name": nameCmd, "add": addCmd, - "log": logCmd, - "diag": diagCmd, + "log": LogCmd, + "diag": DiagCmd, "pin": pinCmd, - "version": versionCmd, + "version": VersionCmd, "config": configCmd, "bootstrap": bootstrapCmd, "mount": mountCmd, "block": blockCmd, - "update": updateCmd, + "update": UpdateCmd, "object": objectCmd, "refs": refsCmd, } diff --git a/core/commands2/update.go b/core/commands2/update.go index 6a3c77a4e..5e14a47e3 100644 --- a/core/commands2/update.go +++ b/core/commands2/update.go @@ -14,7 +14,7 @@ type UpdateOutput struct { NewVersion string } -var updateCmd = &cmds.Command{ +var UpdateCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Downloads and installs updates for IPFS", ShortDescription: "ipfs update is a utility command used to check for updates and apply them.", diff --git a/core/commands2/version.go b/core/commands2/version.go index f9f5a33f3..ce58fb4a5 100644 --- a/core/commands2/version.go +++ b/core/commands2/version.go @@ -9,7 +9,7 @@ type VersionOutput struct { Version string } -var versionCmd = &cmds.Command{ +var VersionCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Outputs the current version of IPFS", ShortDescription: "Returns the version number of IPFS and exits.",