mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 12:20:03 +08:00
cmds2: use cmdDetails on level cmds
This commit is contained in:
@ -78,5 +78,7 @@ var cmdDetailsMap = map[*cmds.Command]cmdDetails{
|
|||||||
commands.DiagCmd: cmdDetails{cannotRunOnClient: true},
|
commands.DiagCmd: cmdDetails{cannotRunOnClient: true},
|
||||||
commands.VersionCmd: cmdDetails{doesNotUseRepo: true},
|
commands.VersionCmd: cmdDetails{doesNotUseRepo: true},
|
||||||
commands.UpdateCmd: cmdDetails{cannotRunOnDaemon: true},
|
commands.UpdateCmd: cmdDetails{cannotRunOnDaemon: true},
|
||||||
|
commands.UpdateCheckCmd: cmdDetails{},
|
||||||
|
commands.UpdateLogCmd: cmdDetails{},
|
||||||
commands.LogCmd: cmdDetails{cannotRunOnClient: true},
|
commands.LogCmd: cmdDetails{cannotRunOnClient: true},
|
||||||
}
|
}
|
||||||
|
@ -267,14 +267,19 @@ func commandShouldRunOnDaemon(req cmds.Request, root *cmds.Command) (bool, error
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, found := root.Subcommands[path[0]]
|
var details cmdDetails
|
||||||
if !found {
|
// find the last command in path that has a cmdDetailsMap entry
|
||||||
return false, fmt.Errorf("subcommand %s should be in root", path[0])
|
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 cmdDetails, found := cmdDetailsMap[cmd]; found {
|
||||||
if !found {
|
details = cmdDetails
|
||||||
details = cmdDetails{} // defaults
|
}
|
||||||
}
|
}
|
||||||
log.Debugf("cmd perms for +%v: %s", path, details.String())
|
log.Debugf("cmd perms for +%v: %s", path, details.String())
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ var UpdateCmd = &cmds.Command{
|
|||||||
},
|
},
|
||||||
Type: &UpdateOutput{},
|
Type: &UpdateOutput{},
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"check": updateCheckCmd,
|
"check": UpdateCheckCmd,
|
||||||
"log": updateLogCmd,
|
"log": UpdateLogCmd,
|
||||||
},
|
},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) ([]byte, error) {
|
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{
|
Helptext: cmds.HelpText{
|
||||||
Tagline: "Checks if updates are available",
|
Tagline: "Checks if updates are available",
|
||||||
ShortDescription: `
|
ShortDescription: `
|
||||||
@ -80,7 +80,7 @@ Nothing will be downloaded or installed.
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateLogCmd = &cmds.Command{
|
var UpdateLogCmd = &cmds.Command{
|
||||||
Helptext: cmds.HelpText{
|
Helptext: cmds.HelpText{
|
||||||
Tagline: "List the changelog for the latest versions of IPFS",
|
Tagline: "List the changelog for the latest versions of IPFS",
|
||||||
ShortDescription: "This command is not yet implemented.",
|
ShortDescription: "This command is not yet implemented.",
|
||||||
|
Reference in New Issue
Block a user