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 2020/02/20 16:53:00 UTC

[mynewt-newtmgr] branch master updated (42db02b -> 80e5c28)

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

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


    from 42db02b  Delete unneccesary `nmxact` binary file
     new 0d6802e  res: Use zero payload when no args specified
     new 80e5c28  res: Correctly parse payload params

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 newtmgr/cli/res.go | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)


[mynewt-newtmgr] 02/02: res: Correctly parse payload params

Posted by cc...@apache.org.
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 80e5c283e6b155177814d1e5040be7807c0d75aa
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Feb 19 16:05:56 2020 -0800

    res: Correctly parse payload params
    
    In `newtmgr <op> <resource>> k1=v1 k2=v2 ...`, the tool was discarding
    all the k=v pairs and encoding an empty map instead.
---
 newtmgr/cli/res.go | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index 51ff7c8..fc422f4 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -255,27 +255,28 @@ func parsePayload(args []string) ([]byte, error) {
 	var val interface{}
 	var err error
 
+	if len(args) == 0 {
+		return nil, nil
+	}
+
 	if resJson {
-		if len(args) == 0 {
-			return nil, nil
-		}
-		itf, err := parsePayloadJson(args[0])
+		val, err = parsePayloadJson(args[0])
 		if err != nil {
 			return nil, err
 		}
 		// Check for zero payload.  Need to return nil explicitly; don't wrap
 		// in interface{}.
-		if itf == nil {
+		if val == nil {
 			return nil, nil
 		}
 	} else {
-		itf, err := parsePayloadMap(args)
+		val, err = parsePayloadMap(args)
 		if err != nil {
 			return nil, err
 		}
 		// Check for zero payload.  Need to return nil explicitly; don't wrap
 		// in interface{}.
-		if itf == nil {
+		if val == nil {
 			return nil, nil
 		}
 	}


[mynewt-newtmgr] 01/02: res: Use zero payload when no args specified

Posted by cc...@apache.org.
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 0d6802eb80b5277936052d5117168d7cd90c7cd8
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Feb 19 08:53:23 2020 -0800

    res: Use zero payload when no args specified
    
    This command:
    
        newtmgr res get /my/res
    
    should send a CoAP GET request with *no* payload.  An optional payload
    can be specified with extra arguments after the resource name.  Since
    there are no extra arguments, there should be no payload.
    
    Prior to this commit, newtmgr was including an empty map as the payload
    in such requests.
    
    The bug was caused by this quirk in Go:
    https://forum.golangbridge.org/t/a-nil-a-b-b-nil-with-pointers-and-interface/10593
    
    In short, if `nil` is assigned to a variable of type `interface{}`, the
    variable will *not* compare equal to `nil`.  An interface variable
    contains two pieces of information: 1) its type, and 2) its value.  The
    variable is not equal to `nil` because `nil` is an *untyped* nil value.
    
    The solution is to return the untyped `nil` rather than the nil
    interface{}.
---
 newtmgr/cli/res.go | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index 7f2e39e..51ff7c8 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -259,17 +259,25 @@ func parsePayload(args []string) ([]byte, error) {
 		if len(args) == 0 {
 			return nil, nil
 		}
-		val, err = parsePayloadJson(args[0])
+		itf, err := parsePayloadJson(args[0])
+		if err != nil {
+			return nil, err
+		}
+		// Check for zero payload.  Need to return nil explicitly; don't wrap
+		// in interface{}.
+		if itf == nil {
+			return nil, nil
+		}
 	} else {
-		val, err = parsePayloadMap(args)
-	}
-	if err != nil {
-		return nil, err
-	}
-
-	if val == nil {
-		// No payload.
-		return nil, nil
+		itf, err := parsePayloadMap(args)
+		if err != nil {
+			return nil, err
+		}
+		// Check for zero payload.  Need to return nil explicitly; don't wrap
+		// in interface{}.
+		if itf == nil {
+			return nil, nil
+		}
 	}
 
 	b, err := nmxutil.EncodeCbor(val)