mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 07:28:20 +08:00
core/commands2: Added function to generate a 'commands' command for a root
This commit is contained in:

committed by
Juan Batiz-Benet

parent
fd8b1930af
commit
f797d13579
@ -11,23 +11,27 @@ type Command struct {
|
|||||||
Subcommands []Command
|
Subcommands []Command
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandsCmd = &cmds.Command{
|
// CommandsCmd takes in a root command,
|
||||||
Description: "List all available commands.",
|
// and returns a command that lists the subcommands in that root
|
||||||
Help: `Lists all available commands (and subcommands) and exits.
|
func CommandsCmd(root *cmds.Command) *cmds.Command {
|
||||||
`,
|
return &cmds.Command{
|
||||||
|
Description: "List all available commands.",
|
||||||
|
Help: `Lists all available commands (and subcommands) and exits.
|
||||||
|
`,
|
||||||
|
|
||||||
Run: func(req cmds.Request) (interface{}, error) {
|
Run: func(req cmds.Request) (interface{}, error) {
|
||||||
root := outputCommand("ipfs", Root)
|
root := outputCommand("ipfs", root)
|
||||||
return &root, nil
|
return &root, nil
|
||||||
},
|
|
||||||
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
|
|
||||||
cmds.Text: func(res cmds.Response) ([]byte, error) {
|
|
||||||
v := res.Output().(*Command)
|
|
||||||
s := formatCommand("", v)
|
|
||||||
return []byte(s), nil
|
|
||||||
},
|
},
|
||||||
},
|
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
|
||||||
Type: &Command{},
|
cmds.Text: func(res cmds.Response) ([]byte, error) {
|
||||||
|
v := res.Output().(*Command)
|
||||||
|
s := formatCommand("", v)
|
||||||
|
return []byte(s), nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Type: &Command{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func outputCommand(name string, cmd *cmds.Command) Command {
|
func outputCommand(name string, cmd *cmds.Command) Command {
|
||||||
|
@ -52,7 +52,7 @@ Plumbing commands:
|
|||||||
var rootSubcommands = map[string]*cmds.Command{
|
var rootSubcommands = map[string]*cmds.Command{
|
||||||
"cat": catCmd,
|
"cat": catCmd,
|
||||||
"ls": lsCmd,
|
"ls": lsCmd,
|
||||||
"commands": commandsCmd,
|
"commands": CommandsCmd(Root),
|
||||||
"name": nameCmd,
|
"name": nameCmd,
|
||||||
"add": addCmd,
|
"add": addCmd,
|
||||||
"log": logCmd,
|
"log": logCmd,
|
||||||
|
Reference in New Issue
Block a user