You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/08/17 18:27:25 UTC

[mynewt-newtmgr] 02/03: newtmgr - Fix resource GET output.

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit 985ad4bfc91242af4dd425df91dfa27bfc4f030e
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Aug 17 11:26:17 2017 -0700

    newtmgr - Fix resource GET output.
---
 newtmgr/cli/res.go | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index 560b30c..0e1c771 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -34,6 +34,30 @@ import (
 	"mynewt.apache.org/newtmgr/nmxact/xact"
 )
 
+func indent(s string, numSpaces int) string {
+	b := make([]byte, numSpaces)
+	for i, _ := range b {
+		b[i] = ' '
+	}
+	tab := string(b)
+
+	nltab := "\n" + tab
+	return tab + strings.Replace(s, "\n", nltab, -1)
+}
+
+func cborValStr(itf interface{}) string {
+	switch v := itf.(type) {
+	case string:
+		return v
+
+	case []byte:
+		return hex.Dump(v)
+
+	default:
+		return fmt.Sprintf("%#v", v)
+	}
+}
+
 func extractResKv(params []string) (map[string]interface{}, error) {
 	m := map[string]interface{}{}
 
@@ -76,17 +100,13 @@ func resGetRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string) {
 		valstr = hex.Dump(sres.Value)
 	} else if len(m) == 0 {
 		valstr = "<empty>"
-	} else if len(m) == 1 {
-		for k, v := range m {
-			valstr = fmt.Sprintf("%s=%+v", k, v)
-		}
 	} else {
 		for k, v := range m {
-			valstr += fmt.Sprintf("\n    %s=%+v", k, v)
+			valstr += fmt.Sprintf("\n    %s\n%s", k, indent(cborValStr(v), 8))
 		}
 	}
 
-	fmt.Printf("%s: %s\n", uri, valstr)
+	fmt.Printf("%s%s\n", uri, valstr)
 }
 
 func resPutRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string,
@@ -150,7 +170,7 @@ func resRunCmd(cmd *cobra.Command, args []string) {
 }
 
 func resCmd() *cobra.Command {
-	resEx := "   newtmgr -c olimex res public mynewt.value.0\n"
+	resEx := "   newtmgr -c olimex res public /dev\n"
 
 	resCmd := &cobra.Command{
 		Use:     "res <type> <uri> [k=v] [k=v] [...]",

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.