Add new version command to ctr

This method allow retrieving the target daemon version information.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2016-05-09 11:38:41 -07:00
parent ba465c17a7
commit efc47463cd

View file

@ -5,9 +5,12 @@ import (
"os"
"time"
netcontext "golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/containerd"
"github.com/docker/containerd/api/grpc/types"
)
const usage = `High performance container daemon cli`
@ -55,6 +58,7 @@ func main() {
containersCommand,
eventsCommand,
stateCommand,
versionCommand,
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") {
@ -67,6 +71,19 @@ func main() {
}
}
var versionCommand = cli.Command{
Name: "version",
Usage: "return the daemon version",
Action: func(context *cli.Context) {
c := getClient(context)
resp, err := c.GetServerVersion(netcontext.Background(), &types.GetServerVersionRequest{})
if err != nil {
fatal(err.Error(), 1)
}
fmt.Printf("daemon version %d.%d.%d commit: %s\n", resp.Major, resp.Minor, resp.Patch, resp.Revision)
},
}
func fatal(err string, code int) {
fmt.Fprintf(os.Stderr, "[ctr] %s\n", err)
panic(Exit{code})