diff --git a/cmd/crictl/container.go b/cmd/crictl/container.go index 9fceea3c69..6d8db18076 100644 --- a/cmd/crictl/container.go +++ b/cmd/crictl/container.go @@ -221,6 +221,10 @@ var containerStatusCommand = cli.Command{ Name: "output, o", Usage: "Output format, One of: json|yaml|table", }, + cli.BoolFlag{ + Name: "quiet, q", + Usage: "Do not show verbose information", + }, }, Action: func(context *cli.Context) error { containerID := context.Args().First() @@ -232,7 +236,7 @@ var containerStatusCommand = cli.Command{ return err } - err := ContainerStatus(runtimeClient, containerID, context.String("output")) + err := ContainerStatus(runtimeClient, containerID, context.String("output"), context.Bool("quiet")) if err != nil { return fmt.Errorf("Getting the status of the container failed: %v", err) } @@ -462,12 +466,17 @@ func RemoveContainer(client pb.RuntimeServiceClient, ID string) error { // ContainerStatus sends a ContainerStatusRequest to the server, and parses // the returned ContainerStatusResponse. -func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error { +func ContainerStatus(client pb.RuntimeServiceClient, ID, output string, quiet bool) error { + verbose := !(quiet) + if output == "" { // default to json output + output = "json" + } if ID == "" { return fmt.Errorf("ID cannot be empty") } request := &pb.ContainerStatusRequest{ ContainerId: ID, + Verbose: verbose, } logrus.Debugf("ContainerStatusRequest: %v", request) r, err := client.ContainerStatus(context.Background(), request) @@ -476,11 +485,15 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error { return err } - if output == "json" || output == "yaml" { + switch output { + case "json", "yaml": return outputStatusInfo(r.Status, r.Info, output) + case "table": // table output is after this switch block + default: + return fmt.Errorf("output option cannot be %s", output) } - // output in table format by default. + // output in table format fmt.Printf("ID: %s\n", r.Status.Id) if r.Status.Metadata != nil { if r.Status.Metadata.Name != "" { @@ -504,6 +517,9 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID, output string) error { } fmt.Printf("Exit Code: %v\n", r.Status.ExitCode) } + if verbose { + fmt.Printf("Info: %v\n", r.GetInfo()) + } return nil } diff --git a/cmd/crictl/image.go b/cmd/crictl/image.go index cc6b4fbe69..2d154ef86b 100644 --- a/cmd/crictl/image.go +++ b/cmd/crictl/image.go @@ -187,6 +187,10 @@ var imageStatusCommand = cli.Command{ Name: "output, o", Usage: "Output format, One of: json|yaml|table", }, + cli.BoolFlag{ + Name: "quiet, q", + Usage: "Do not show verbose information", + }, }, Action: func(context *cli.Context) error { id := context.Args().First() @@ -198,7 +202,8 @@ var imageStatusCommand = cli.Command{ return err } - r, err := ImageStatus(imageClient, id) + verbose := !(context.Bool("quiet")) + r, err := ImageStatus(imageClient, id, verbose) if err != nil { return fmt.Errorf("image status request failed: %v", err) } @@ -208,11 +213,19 @@ var imageStatusCommand = cli.Command{ } output := context.String("output") - if output == "json" || output == "yaml" { + if output == "" { // default to json output + output = "json" + } + + switch output { + case "json", "yaml": return outputStatusInfo(r.Image, r.Info, output) + case "table": // table output is after this switch block + default: + return fmt.Errorf("output option cannot be %s", output) } - // output in table format by default. + // otherwise output in table format fmt.Printf("ID: %s\n", image.Id) for _, tag := range image.RepoTags { fmt.Printf("Tag: %s\n", tag) @@ -222,6 +235,9 @@ var imageStatusCommand = cli.Command{ } size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3) fmt.Printf("Size: %s\n", size) + if verbose { + fmt.Printf("Info: %v\n", r.GetInfo()) + } return nil }, @@ -241,7 +257,8 @@ var removeImageCommand = cli.Command{ return err } - status, err := ImageStatus(imageClient, id) + var verbose = false + status, err := ImageStatus(imageClient, id, verbose) if err != nil { return fmt.Errorf("image status request failed: %v", err) } @@ -342,8 +359,11 @@ func ListImages(client pb.ImageServiceClient, image string) (resp *pb.ListImages // ImageStatus sends an ImageStatusRequest to the server, and parses // the returned ImageStatusResponse. -func ImageStatus(client pb.ImageServiceClient, image string) (resp *pb.ImageStatusResponse, err error) { - request := &pb.ImageStatusRequest{Image: &pb.ImageSpec{Image: image}} +func ImageStatus(client pb.ImageServiceClient, image string, verbose bool) (resp *pb.ImageStatusResponse, err error) { + request := &pb.ImageStatusRequest{ + Image: &pb.ImageSpec{Image: image}, + Verbose: verbose, + } logrus.Debugf("ImageStatusRequest: %v", request) resp, err = client.ImageStatus(context.Background(), request) logrus.Debugf("ImageStatusResponse: %v", resp) diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index c280aafb9c..7d618deb22 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -128,6 +128,10 @@ var podSandboxStatusCommand = cli.Command{ Name: "output, o", Usage: "Output format, One of: json|yaml|table", }, + cli.BoolFlag{ + Name: "quiet, q", + Usage: "Do not show verbose information", + }, }, Action: func(context *cli.Context) error { id := context.Args().First() @@ -139,7 +143,7 @@ var podSandboxStatusCommand = cli.Command{ return err } - err := PodSandboxStatus(runtimeClient, id, context.String("output")) + err := PodSandboxStatus(runtimeClient, id, context.String("output"), context.Bool("quiet")) if err != nil { return fmt.Errorf("getting the pod sandbox status failed: %v", err) } @@ -275,20 +279,32 @@ func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error { // PodSandboxStatus sends a PodSandboxStatusRequest to the server, and parses // the returned PodSandboxStatusResponse. -func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string) error { +func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string, quiet bool) error { + verbose := !(quiet) + if output == "" { // default to json output + output = "json" + } if ID == "" { return fmt.Errorf("ID cannot be empty") } - request := &pb.PodSandboxStatusRequest{PodSandboxId: ID} + + request := &pb.PodSandboxStatusRequest{ + PodSandboxId: ID, + Verbose: verbose, + } logrus.Debugf("PodSandboxStatusRequest: %v", request) - r, err := client.PodSandboxStatus(context.Background(), &pb.PodSandboxStatusRequest{PodSandboxId: ID}) + r, err := client.PodSandboxStatus(context.Background(), request) logrus.Debugf("PodSandboxStatusResponse: %v", r) if err != nil { return err } - if output == "json" || output == "yaml" { + switch output { + case "json", "yaml": return outputStatusInfo(r.Status, r.Info, output) + case "table": // table output is after this switch block + default: + return fmt.Errorf("output option cannot be %s", output) } // output in table format by default. @@ -324,6 +340,10 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID, output string) error { fmt.Printf("\t%s -> %s\n", k, r.Status.Annotations[k]) } } + if verbose { + fmt.Printf("Info: %v\n", r.GetInfo()) + } + return nil }