add close handler to cap cmd
@@ -38,6 +38,9 @@ var capabilitiesCmd = &cobra.Command{
Short: "query targets gnmi capabilities",
RunE: func(cmd *cobra.Command, args []string) error {
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ setupCloseHandler(cancel)
var err error
addresses := viper.GetStringSlice("address")
if len(addresses) == 0 {
@@ -78,11 +81,11 @@ var capabilitiesCmd = &cobra.Command{
}
client := gnmi.NewGNMIClient(conn)
- ctx, cancel := context.WithCancel(context.Background())
+ nctx, cancel := context.WithCancel(ctx)
defer cancel()
- ctx = metadata.AppendToOutgoingContext(ctx, "username", username, "password", password)
+ nctx = metadata.AppendToOutgoingContext(nctx, "username", username, "password", password)
- response, err := client.Capabilities(ctx, req)
+ response, err := client.Capabilities(nctx, req)
if err != nil {
logger.Printf("error sending capabilities request: %v", err)
return
