Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
print returned values only in get cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
karimra committed May 10, 2020
1 parent cc4f4c0 commit 5a4a0e2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ var getCmd = &cobra.Command{
if len(addresses) > 1 && !viper.GetBool("no-prefix") {
printPrefix = fmt.Sprintf("[%s] ", address)
}
valsOnly := viper.GetBool("get-values-only")
lock.Lock()
for _, notif := range response.Notification {
fmt.Printf("%stimestamp: %d\n", printPrefix, notif.Timestamp)
fmt.Printf("%sprefix: %s\n", printPrefix, gnmiPathToXPath(notif.Prefix))
fmt.Printf("%salias: %s\n", printPrefix, notif.Alias)
if !valsOnly {
fmt.Printf("%stimestamp: %d\n", printPrefix, notif.Timestamp)
fmt.Printf("%sprefix: %s\n", printPrefix, gnmiPathToXPath(notif.Prefix))
fmt.Printf("%salias: %s\n", printPrefix, notif.Alias)
}
for _, upd := range notif.Update {
if upd.Val == nil {
if debug {
Expand Down Expand Up @@ -186,7 +189,7 @@ var getCmd = &cobra.Command{
case *gnmi.TypedValue_JsonVal:
jsondata = upd.Val.GetJsonVal()
}
if debug {
if debug && !valsOnly {
fmt.Printf("%supdate value type: %T\n", printPrefix, upd.Val.Value)
}
if len(jsondata) > 0 {
Expand All @@ -200,9 +203,17 @@ var getCmd = &cobra.Command{
log.Printf("error marshling jsonVal '%s'", value)
continue
}
fmt.Printf("%s%s: %s\n", printPrefix, gnmiPathToXPath(upd.Path), data)
if !valsOnly {
fmt.Printf("%s%s: %s\n", printPrefix, gnmiPathToXPath(upd.Path), data)
} else {
fmt.Printf("%s\n", data)
}
} else if value != nil {
fmt.Printf("%s%s: %s\n", printPrefix, gnmiPathToXPath(upd.Path), value)
if !valsOnly {
fmt.Printf("%s%s: %s\n", printPrefix, gnmiPathToXPath(upd.Path), value)
} else {
fmt.Printf("%s\n", value)
}
}
}
}
Expand All @@ -223,8 +234,10 @@ func init() {
getCmd.Flags().StringP("prefix", "", "", "get request prefix")
getCmd.Flags().StringP("model", "", "", "get request model")
getCmd.Flags().StringP("type", "t", "ALL", "the type of data that is requested from the target. one of: ALL, CONFIG, STATE, OPERATIONAL")
getCmd.Flags().BoolP("values-only", "", false, "output returned values only, useful for file redirection")
viper.BindPFlag("get-path", getCmd.Flags().Lookup("path"))
viper.BindPFlag("get-prefix", getCmd.Flags().Lookup("prefix"))
viper.BindPFlag("get-model", getCmd.Flags().Lookup("model"))
viper.BindPFlag("get-type", getCmd.Flags().Lookup("type"))
viper.BindPFlag("get-values-only", getCmd.Flags().Lookup("values-only"))
}

0 comments on commit 5a4a0e2

Please sign in to comment.