Skip to content

Commit

Permalink
adding verbose output switch for inspect
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Brown <[email protected]>
  • Loading branch information
mikebrow committed Dec 1, 2017
1 parent 80a7c13 commit faa6682
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 != "" {
Expand All @@ -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
}
Expand Down

0 comments on commit faa6682

Please sign in to comment.