Commit e0ba14c0 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

cmds2: use cmdDetails on level cmds

parent 0eeed7cc
......@@ -78,5 +78,7 @@ var cmdDetailsMap = map[*cmds.Command]cmdDetails{
commands.DiagCmd: cmdDetails{cannotRunOnClient: true},
commands.VersionCmd: cmdDetails{doesNotUseRepo: true},
commands.UpdateCmd: cmdDetails{cannotRunOnDaemon: true},
commands.UpdateCheckCmd: cmdDetails{},
commands.UpdateLogCmd: cmdDetails{},
commands.LogCmd: cmdDetails{cannotRunOnClient: true},
}
......@@ -267,14 +267,19 @@ func commandShouldRunOnDaemon(req cmds.Request, root *cmds.Command) (bool, error
return false, nil
}
cmd, found := root.Subcommands[path[0]]
if !found {
return false, fmt.Errorf("subcommand %s should be in root", path[0])
}
var details cmdDetails
// find the last command in path that has a cmdDetailsMap entry
cmd := root
for _, cmp := range path {
var found bool
cmd, found = cmd.Subcommands[cmp]
if !found {
return false, fmt.Errorf("subcommand %s should be in root", cmp)
}
details, found := cmdDetailsMap[cmd]
if !found {
details = cmdDetails{} // defaults
if cmdDetails, found := cmdDetailsMap[cmd]; found {
details = cmdDetails
}
}
log.Debugf("cmd perms for +%v: %s", path, details.String())
......
......@@ -29,8 +29,8 @@ var UpdateCmd = &cmds.Command{
},
Type: &UpdateOutput{},
Subcommands: map[string]*cmds.Command{
"check": updateCheckCmd,
"log": updateLogCmd,
"check": UpdateCheckCmd,
"log": UpdateLogCmd,
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) ([]byte, error) {
......@@ -47,7 +47,7 @@ var UpdateCmd = &cmds.Command{
},
}
var updateCheckCmd = &cmds.Command{
var UpdateCheckCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Checks if updates are available",
ShortDescription: `
......@@ -80,7 +80,7 @@ Nothing will be downloaded or installed.
},
}
var updateLogCmd = &cmds.Command{
var UpdateLogCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List the changelog for the latest versions of IPFS",
ShortDescription: "This command is not yet implemented.",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment