提交 bb8d4ebd 作者: Juan Batiz-Benet

cmds2: cmdDetailsMap

上级 ef0826ac
...@@ -13,13 +13,16 @@ var Root = &cmds.Command{ ...@@ -13,13 +13,16 @@ var Root = &cmds.Command{
Helptext: commands.Root.Helptext, 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). // 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. // They can override subcommands in commands.Root by defining a subcommand with the same name.
var localCommands = map[string]*cmds.Command{ var localCommands = map[string]*cmds.Command{
"daemon": daemonCmd, // TODO name "daemon": daemonCmd,
"init": initCmd, // TODO name "init": initCmd,
"tour": cmdTour, "tour": tourCmd,
"commands": commands.CommandsCmd(Root), "commands": commandsClientCmd,
} }
var localMap = make(map[*cmds.Command]bool) var localMap = make(map[*cmds.Command]bool)
...@@ -45,3 +48,24 @@ func isLocal(cmd *cmds.Command) bool { ...@@ -45,3 +48,24 @@ func isLocal(cmd *cmds.Command) bool {
_, found := localMap[cmd] _, found := localMap[cmd]
return found 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},
}
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
tour "github.com/jbenet/go-ipfs/tour" tour "github.com/jbenet/go-ipfs/tour"
) )
var cmdTour = &cmds.Command{ var tourCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "An introduction to IPFS", Tagline: "An introduction to IPFS",
ShortDescription: ` ShortDescription: `
......
...@@ -37,9 +37,9 @@ Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'. ...@@ -37,9 +37,9 @@ Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'.
Type: bootstrapListCmd.Type, Type: bootstrapListCmd.Type,
Subcommands: map[string]*cmds.Command{ Subcommands: map[string]*cmds.Command{
"list": bootstrapListCmd, "list": bootstrapListCmd,
"add": bootstrapAddCmd, "add": bootstrapAddCmd,
"rm": bootstrapRemoveCmd, "rm": bootstrapRemoveCmd,
}, },
} }
......
...@@ -28,7 +28,7 @@ type DiagnosticOutput struct { ...@@ -28,7 +28,7 @@ type DiagnosticOutput struct {
Peers []DiagnosticPeer Peers []DiagnosticPeer
} }
var diagCmd = &cmds.Command{ var DiagCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Generates diagnostic reports", Tagline: "Generates diagnostic reports",
}, },
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
// we convert it at this step. // we convert it at this step.
var logAllKeyword = "all" var logAllKeyword = "all"
var logCmd = &cmds.Command{ var LogCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Change the logging level", Tagline: "Change the logging level",
ShortDescription: ` ShortDescription: `
......
...@@ -51,21 +51,24 @@ Plumbing commands: ...@@ -51,21 +51,24 @@ Plumbing commands:
}, },
} }
// commandsDaemonCmd is the "ipfs commands" command for daemon
var CommandsDaemonCmd = CommandsCmd(Root)
var rootSubcommands = map[string]*cmds.Command{ var rootSubcommands = map[string]*cmds.Command{
"cat": catCmd, "cat": catCmd,
"ls": lsCmd, "ls": lsCmd,
"commands": CommandsCmd(Root), "commands": CommandsDaemonCmd,
"name": nameCmd, "name": nameCmd,
"add": addCmd, "add": addCmd,
"log": logCmd, "log": LogCmd,
"diag": diagCmd, "diag": DiagCmd,
"pin": pinCmd, "pin": pinCmd,
"version": versionCmd, "version": VersionCmd,
"config": configCmd, "config": configCmd,
"bootstrap": bootstrapCmd, "bootstrap": bootstrapCmd,
"mount": mountCmd, "mount": mountCmd,
"block": blockCmd, "block": blockCmd,
"update": updateCmd, "update": UpdateCmd,
"object": objectCmd, "object": objectCmd,
"refs": refsCmd, "refs": refsCmd,
} }
......
...@@ -14,7 +14,7 @@ type UpdateOutput struct { ...@@ -14,7 +14,7 @@ type UpdateOutput struct {
NewVersion string NewVersion string
} }
var updateCmd = &cmds.Command{ var UpdateCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Downloads and installs updates for IPFS", Tagline: "Downloads and installs updates for IPFS",
ShortDescription: "ipfs update is a utility command used to check for updates and apply them.", ShortDescription: "ipfs update is a utility command used to check for updates and apply them.",
......
...@@ -9,7 +9,7 @@ type VersionOutput struct { ...@@ -9,7 +9,7 @@ type VersionOutput struct {
Version string Version string
} }
var versionCmd = &cmds.Command{ var VersionCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "Outputs the current version of IPFS", Tagline: "Outputs the current version of IPFS",
ShortDescription: "Returns the version number of IPFS and exits.", ShortDescription: "Returns the version number of IPFS and exits.",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论