separate custom capabilities response print func
@@ -495,13 +495,33 @@ func printMsg(address string, msg proto.Message) error {
switch msg := msg.ProtoReflect().Interface().(type) {
case *gnmi.CapabilityResponse:
if len(viper.GetString("format")) == 0 {
+ printCapResponse(printPrefix, msg)
+ return nil
+ }
+ }
+ mo := collector.MarshalOptions{
+ Multiline: true,
+ Indent: " ",
+ Format: viper.GetString("format"),
+ }
+ b, err := mo.Marshal(msg, map[string]string{"address": address})
+ if err != nil {
+ return err
+ }
+ sb := strings.Builder{}
+ sb.Write(b)
+ fmt.Printf("%s\n", indent(printPrefix, sb.String()))
+ return nil
+}
+
+func printCapResponse(printPrefix string, msg *gnmi.CapabilityResponse) {
sb := strings.Builder{}
sb.WriteString(printPrefix)
sb.WriteString("gNMI version: ")
sb.WriteString(msg.GNMIVersion)
sb.WriteString("\n")
if viper.GetBool("version") {
- return nil
+ return
}
sb.WriteString(printPrefix)
sb.WriteString("supported models:\n")
@@ -524,20 +544,4 @@ func printMsg(address string, msg proto.Message) error {
sb.WriteString("\n")
}
fmt.Printf("%s\n", indent(printPrefix, sb.String()))
- return nil
- }
- }
- mo := collector.MarshalOptions{
- Multiline: true,
- Indent: " ",
- Format: viper.GetString("format"),
- }
- b, err := mo.Marshal(msg, map[string]string{"address": address})
- if err != nil {
- return err
- }
- sb := strings.Builder{}
- sb.Write(b)
- fmt.Printf("%s\n", indent(printPrefix, sb.String()))
- return nil
}
