@cryptotaxi247 / kubo / commits / bb8d4ebd6

cmds2: cmdDetailsMap

Juan Batiz-Benet committed Nov 13, 2014 at 03:42 UTC bb8d4ebd6ba6e2004c3b03512dc57ff6c5d9677a
8 files changed +44 -17
cmd/ipfs2/ipfs.go
+28 -4
@@ -13,13 +13,16 @@ var Root = &cmds.Command{
13 Helptext: commands.Root.Helptext,
14 }
15
16 +// commandsClientCmd is the "ipfs commands" command for local cli
17 +var commandsClientCmd = commands.CommandsCmd(Root)
18 +
19 // Commands in localCommands should always be run locally (even if daemon is running).
20 // They can override subcommands in commands.Root by defining a subcommand with the same name.
21 var localCommands = map[string]*cmds.Command{
19 - "daemon": daemonCmd, // TODO name
20 - "init": initCmd, // TODO name
21 - "tour": cmdTour,
22 - "commands": commands.CommandsCmd(Root),
22 + "daemon": daemonCmd,
23 + "init": initCmd,
24 + "tour": tourCmd,
25 + "commands": commandsClientCmd,
26 }
27 var localMap = make(map[*cmds.Command]bool)
28
@@ -45,3 +48,24 @@ func isLocal(cmd *cmds.Command) bool {
48 _, found := localMap[cmd]
49 return found
50 }
51 +
52 +type cmdDetails struct {
53 + cannotRunOnClient bool
54 + cannotRunOnDaemon bool
55 + doesNotUseRepo bool
56 +}
57 +
58 +// "What is this madness!?" you ask. Our commands have the unfortunate problem of
59 +// not being able to run on all the same contexts. This map describes these
60 +// properties so that other code can make decisions about whether to invoke a
61 +// command or return an error to the user.
62 +var cmdDetailsMap = map[*cmds.Command]cmdDetails{
63 + initCmd: cmdDetails{cannotRunOnDaemon: true, doesNotUseRepo: true},
64 + daemonCmd: cmdDetails{cannotRunOnDaemon: true},
65 + commandsClientCmd: cmdDetails{doesNotUseRepo: true},
66 + commands.CommandsDaemonCmd: cmdDetails{doesNotUseRepo: true},
67 + commands.DiagCmd: cmdDetails{cannotRunOnClient: true},
68 + commands.VersionCmd: cmdDetails{doesNotUseRepo: true},
69 + commands.UpdateCmd: cmdDetails{cannotRunOnDaemon: true},
70 + commands.LogCmd: cmdDetails{cannotRunOnClient: true},
71 +}
cmd/ipfs2/tour.go
+1 -1
@@ -13,7 +13,7 @@ import (
13 tour "github.com/jbenet/go-ipfs/tour"
14 )
15
16 -var cmdTour = &cmds.Command{
16 +var tourCmd = &cmds.Command{
17 Helptext: cmds.HelpText{
18 Tagline: "An introduction to IPFS",
19 ShortDescription: `
core/commands2/bootstrap.go
+3 -3
@@ -37,9 +37,9 @@ Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'.
37 Type: bootstrapListCmd.Type,
38
39 Subcommands: map[string]*cmds.Command{
40 - "list": bootstrapListCmd,
41 - "add": bootstrapAddCmd,
42 - "rm": bootstrapRemoveCmd,
40 + "list": bootstrapListCmd,
41 + "add": bootstrapAddCmd,
42 + "rm": bootstrapRemoveCmd,
43 },
44 }
45
core/commands2/diag.go
+1 -1
@@ -28,7 +28,7 @@ type DiagnosticOutput struct {
28 Peers []DiagnosticPeer
29 }
30
31 -var diagCmd = &cmds.Command{
31 +var DiagCmd = &cmds.Command{
32 Helptext: cmds.HelpText{
33 Tagline: "Generates diagnostic reports",
34 },
core/commands2/log.go
+1 -1
@@ -13,7 +13,7 @@ import (
13 // we convert it at this step.
14 var logAllKeyword = "all"
15
16 -var logCmd = &cmds.Command{
16 +var LogCmd = &cmds.Command{
17 Helptext: cmds.HelpText{
18 Tagline: "Change the logging level",
19 ShortDescription: `
core/commands2/root.go
+8 -5
@@ -51,21 +51,24 @@ Plumbing commands:
51 },
52 }
53
54 +// commandsDaemonCmd is the "ipfs commands" command for daemon
55 +var CommandsDaemonCmd = CommandsCmd(Root)
56 +
57 var rootSubcommands = map[string]*cmds.Command{
58 "cat": catCmd,
59 "ls": lsCmd,
57 - "commands": CommandsCmd(Root),
60 + "commands": CommandsDaemonCmd,
61 "name": nameCmd,
62 "add": addCmd,
60 - "log": logCmd,
61 - "diag": diagCmd,
63 + "log": LogCmd,
64 + "diag": DiagCmd,
65 "pin": pinCmd,
63 - "version": versionCmd,
66 + "version": VersionCmd,
67 "config": configCmd,
68 "bootstrap": bootstrapCmd,
69 "mount": mountCmd,
70 "block": blockCmd,
68 - "update": updateCmd,
71 + "update": UpdateCmd,
72 "object": objectCmd,
73 "refs": refsCmd,
74 }
core/commands2/update.go
+1 -1
@@ -14,7 +14,7 @@ type UpdateOutput struct {
14 NewVersion string
15 }
16
17 -var updateCmd = &cmds.Command{
17 +var UpdateCmd = &cmds.Command{
18 Helptext: cmds.HelpText{
19 Tagline: "Downloads and installs updates for IPFS",
20 ShortDescription: "ipfs update is a utility command used to check for updates and apply them.",
core/commands2/version.go
+1 -1
@@ -9,7 +9,7 @@ type VersionOutput struct {
9 Version string
10 }
11
12 -var versionCmd = &cmds.Command{
12 +var VersionCmd = &cmds.Command{
13 Helptext: cmds.HelpText{
14 Tagline: "Outputs the current version of IPFS",
15 ShortDescription: "Returns the version number of IPFS and exits.",