Add ctr c info --spec flag to output spec

This flag makes it easy to view only the OCI spec for the container.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2020-03-05 11:54:13 -05:00
parent ca66f3dd5d
commit 00e6be9f45

View File

@ -248,6 +248,12 @@ var infoCommand = cli.Command{
Name: "info", Name: "info",
Usage: "get info about a container", Usage: "get info about a container",
ArgsUsage: "CONTAINER", ArgsUsage: "CONTAINER",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "spec",
Usage: "only display the spec",
},
},
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
id := context.Args().First() id := context.Args().First()
if id == "" { if id == "" {
@ -266,6 +272,14 @@ var infoCommand = cli.Command{
if err != nil { if err != nil {
return err return err
} }
if context.Bool("spec") {
v, err := typeurl.UnmarshalAny(info.Spec)
if err != nil {
return err
}
commands.PrintAsJSON(v)
return nil
}
if info.Spec != nil && info.Spec.Value != nil { if info.Spec != nil && info.Spec.Value != nil {
v, err := typeurl.UnmarshalAny(info.Spec) v, err := typeurl.UnmarshalAny(info.Spec)