johnmccabe commented on a change in pull request #78: BROOKLYN-586 update br to 
replace obsolete jsonpath package
URL: https://github.com/apache/brooklyn-client/pull/78#discussion_r320487082
 
 

 ##########
 File path: cli/models/catalog.go
 ##########
 @@ -159,36 +168,50 @@ func (summary *CatalogEntitySummary) displayAsTable() 
(err error){
        return err
 }
 
+func resultsBackToJson(wr io.Writer, values []reflect.Value, raw bool) error {
+       for i, r := range values {
+               object := r.Interface()
 
+               jsonText, err := json.Marshal(object)
+               if err != nil {
+                       return fmt.Errorf("error converting object to JSON: 
%s", err)
+               }
 
-func displayAsJson(v interface{}, jsonPath string) (err error) {
-       marshalled, err := json.Marshal(v)
-       if err != nil {
-               return err
-       }
-       // a convenient special case
-       if "$" == jsonPath {
-               fmt.Printf("%s", string(marshalled))
-               return nil
+               if r.Kind() == reflect.String && raw {
+                       stringWithQuotes := string(jsonText)
+                       trimLeft := strings.TrimPrefix(stringWithQuotes, `"`)
+                       withoutQuotes := strings.TrimSuffix(trimLeft, `"`)
+                       jsonText = []byte(withoutQuotes)
+               }
+
+               if i != len(values)-1 {
+                       jsonText = append(jsonText, ' ')
+               }
+               if _, err := wr.Write(jsonText); err != nil {
+                       return err
+               }
        }
+       return nil
+}
+
+func displayAsJson(v interface{}, displayPath string, raw bool) (err error) {
 
 Review comment:
   I'd dump the named return while you're touching this.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to