Provide more useful help information for ctr

`ctr containers/checkpoints` contains lots of important subcommands,
but now help command can't show subcommands. Adding subcommands to
help information will avoid user from digging into the code for
getting necessary command list.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei 2016-04-13 15:03:53 +08:00
parent 21364997bb
commit 59720469ac
3 changed files with 44 additions and 23 deletions

View File

@ -14,7 +14,7 @@ The included `ctr` command-line tool allows you interact with the containerd dae
$ sudo ctr containers start redis /containers/redis $ sudo ctr containers start redis /containers/redis
$ sudo ctr containers list $ sudo ctr containers list
ID PATH STATUS PROCESSES ID PATH STATUS PROCESSES
1 /containers/redis running 14063 redis /containers/redis running 14063
``` ```
`/containers/redis` is the path to an OCI bundle. [See the docs for more information.](docs/bundle.md) `/containers/redis` is the path to an OCI bundle. [See the docs for more information.](docs/bundle.md)

View File

@ -10,14 +10,24 @@ import (
netcontext "golang.org/x/net/context" netcontext "golang.org/x/net/context"
) )
var checkpointSubCmds = []cli.Command{
listCheckpointCommand,
createCheckpointCommand,
deleteCheckpointCommand,
}
var checkpointCommand = cli.Command{ var checkpointCommand = cli.Command{
Name: "checkpoints", Name: "checkpoints",
Usage: "list all checkpoints", Usage: "list all checkpoints",
Subcommands: []cli.Command{ ArgsUsage: "COMMAND [arguments...]",
listCheckpointCommand, Subcommands: checkpointSubCmds,
createCheckpointCommand, Description: func() string {
deleteCheckpointCommand, desc := "\n COMMAND:\n"
}, for _, command := range checkpointSubCmds {
desc += fmt.Sprintf(" %-10.10s%s\n", command.Name, command.Usage)
}
return desc
}(),
Action: listCheckpoints, Action: listCheckpoints,
} }

View File

@ -41,20 +41,30 @@ func getClient(ctx *cli.Context) types.APIClient {
return types.NewAPIClient(conn) return types.NewAPIClient(conn)
} }
var contSubCmds = []cli.Command{
execCommand,
killCommand,
listCommand,
pauseCommand,
resumeCommand,
startCommand,
statsCommand,
watchCommand,
updateCommand,
}
var containersCommand = cli.Command{ var containersCommand = cli.Command{
Name: "containers", Name: "containers",
Usage: "interact with running containers", Usage: "interact with running containers",
Subcommands: []cli.Command{ ArgsUsage: "COMMAND [arguments...]",
execCommand, Subcommands: contSubCmds,
killCommand, Description: func() string {
listCommand, desc := "\n COMMAND:\n"
pauseCommand, for _, command := range contSubCmds {
resumeCommand, desc += fmt.Sprintf(" %-10.10s%s\n", command.Name, command.Usage)
startCommand, }
statsCommand, return desc
watchCommand, }(),
updateCommand,
},
Action: listContainers, Action: listContainers,
} }
@ -107,8 +117,9 @@ func listContainers(context *cli.Context) {
} }
var startCommand = cli.Command{ var startCommand = cli.Command{
Name: "start", Name: "start",
Usage: "start a container", Usage: "start a container",
ArgsUsage: "ID BundlePath",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "checkpoint,c", Name: "checkpoint,c",