1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 18:13:54 +08:00

cmds2: use cmdDetails on level cmds

This commit is contained in:
Juan Batiz-Benet
2014-11-13 22:53:14 -08:00
parent 0eeed7cc68
commit e0ba14c0eb
3 changed files with 18 additions and 11 deletions

View File

@ -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},
}

View File

@ -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())

View File

@ -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.",