Skip to content

Commit 841ddb6

Browse files
author
Yanqiang Miao
committed
Rename 'crictl info' to 'crictl version' and add verbose for crictl status
Signed-off-by: Yanqiang Miao <[email protected]>
1 parent dfc2e77 commit 841ddb6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

cmd/crictl/status.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"bytes"
21+
"encoding/json"
2022
"fmt"
2123
"os"
2224
"text/tabwriter"
@@ -29,10 +31,16 @@ import (
2931

3032
var runtimeStatusCommand = cli.Command{
3133
Name: "status",
32-
Usage: "Display status of the container runtime",
34+
Usage: "Display status and extra information of the container runtime",
3335
ArgsUsage: "",
36+
Flags: []cli.Flag{
37+
cli.BoolFlag{
38+
Name: "verbose, v",
39+
Usage: "Shows extra status information",
40+
},
41+
},
3442
Action: func(context *cli.Context) error {
35-
err := Status(runtimeClient)
43+
err := Status(runtimeClient, context.Bool("verbose"))
3644
if err != nil {
3745
return fmt.Errorf("Getting status of runtime failed: %v", err)
3846
}
@@ -43,8 +51,8 @@ var runtimeStatusCommand = cli.Command{
4351
}
4452

4553
// Status sends a StatusRequest to the server, and parses the returned StatusResponse.
46-
func Status(client pb.RuntimeServiceClient) error {
47-
request := &pb.StatusRequest{}
54+
func Status(client pb.RuntimeServiceClient, verbose bool) error {
55+
request := &pb.StatusRequest{Verbose: verbose}
4856
logrus.Debugf("StatusRequest: %v", request)
4957
r, err := client.Status(context.Background(), request)
5058
logrus.Debugf("StatusResponse: %v", r)
@@ -57,6 +65,20 @@ func Status(client pb.RuntimeServiceClient) error {
5765
for _, c := range r.GetStatus().GetConditions() {
5866
fmt.Fprintf(w, "%s\t%v\t%s\t%s\n", c.Type, c.Status, c.Reason, c.Message)
5967
}
68+
if verbose {
69+
fmt.Fprintln(w, "Extra Info: ")
70+
for key, value := range r.Info {
71+
var buf *bytes.Buffer
72+
err := json.Indent(buf, []byte(value), "", " ")
73+
if err != nil {
74+
return err
75+
}
76+
77+
fmt.Fprintf(w, " %s: ", key)
78+
fmt.Fprintf(w, string(buf.Bytes()))
79+
}
80+
}
6081
w.Flush()
82+
6183
return nil
6284
}

cmd/crictl/info.go cmd/crictl/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
)
3131

3232
var runtimeVersionCommand = cli.Command{
33-
Name: "info",
33+
Name: "version",
3434
Usage: "Display runtime version information",
3535
Action: func(context *cli.Context) error {
3636
err := Version(runtimeClient, criClientVersion)

0 commit comments

Comments
 (0)