From 801da72baa7ce3f079ce616d8d672298f6619f38 Mon Sep 17 00:00:00 2001 From: Jaesang Lee Date: Tue, 15 Mar 2022 08:21:49 +0000 Subject: [PATCH] Fix tks for cluster - Add global flag for verbose feature - Remove unneeded slice --- cmd/cluster_delete.go | 28 ++++++++++++++++------------ cmd/root.go | 2 +- go.mod | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/cluster_delete.go b/cmd/cluster_delete.go index 5a77b6b..87664ed 100644 --- a/cmd/cluster_delete.go +++ b/cmd/cluster_delete.go @@ -43,6 +43,7 @@ tks cluster delete `, fmt.Println("Usage: tks cluster delete ") os.Exit(1) } + var conn *grpc.ClientConn conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { @@ -51,24 +52,27 @@ tks cluster delete `, defer conn.Close() client := pb.NewClusterLcmServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) defer cancel() - data := make([]pb.IDRequest, 1) - data[0].Id = args[0] + data := pb.IDRequest{} + data.Id = args[0] m := protojson.MarshalOptions{ Indent: " ", UseProtoNames: true, } - jsonBytes, _ := m.Marshal(&data[0]) - fmt.Println("Proto Json data...") - fmt.Println(string(jsonBytes)) - r, err := client.DeleteCluster(ctx, &data[0]) + jsonBytes, _ := m.Marshal(&data) + verbose, err := rootCmd.PersistentFlags().GetBool("verbose") + if verbose { + fmt.Println("Proto Json data...") + fmt.Println(string(jsonBytes)) + } + r, err := client.DeleteCluster(ctx, &data) fmt.Println(r) - if err != nil { - fmt.Println(err) - } else { - fmt.Println("The request to delete cluster ", args[0], " was accepted.") - } + if err != nil { + fmt.Println(err) + } else { + fmt.Println("The request to delete cluster ", args[0], " was accepted.") + } }, } diff --git a/cmd/root.go b/cmd/root.go index 590f7f1..d0fa81b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -55,7 +55,7 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tks-client.yaml)") - + rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") // Cobra also supports local flags, which will only run // when this action is called directly. rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") diff --git a/go.mod b/go.mod index 1d8d828..32ad955 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/openinfradev/tks-proto v0.0.6-0.20220304011855-99ac351f420f github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.9.0 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.7.0 // indirect golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect google.golang.org/genproto v0.0.0-20211021150943-2b146023228c // indirect