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 2016/10/13 18:27:38 UTC

incubator-mynewt-newt git commit: newtmgr - Sort list in "conn show" output.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop f936c989e -> c49488c77


newtmgr - Sort list in "conn show" output.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/c49488c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/c49488c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/c49488c7

Branch: refs/heads/develop
Commit: c49488c770c101ed6fe283fa4040909aea914135
Parents: f936c98
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 13 10:00:49 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Oct 13 11:27:33 2016 -0700

----------------------------------------------------------------------
 newtmgr/config/connprofile.go | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c49488c7/newtmgr/config/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/config/connprofile.go b/newtmgr/config/connprofile.go
index d03c536..50564b2 100644
--- a/newtmgr/config/connprofile.go
+++ b/newtmgr/config/connprofile.go
@@ -25,6 +25,7 @@ import (
 
 	"encoding/json"
 	"io/ioutil"
+	"sort"
 
 	"mynewt.apache.org/newt/util"
 )
@@ -42,10 +43,10 @@ type NewtmgrConnProfile interface {
 }
 
 type ConnProfile struct {
-	MyName       string
-	MyType       string
-	MyConnString string
-	MyDeviceAddress []byte
+	MyName              string
+	MyType              string
+	MyConnString        string
+	MyDeviceAddress     []byte
 	MyDeviceAddressType uint8
 }
 
@@ -98,6 +99,33 @@ func (cpm *ConnProfileMgr) Init() error {
 	return nil
 }
 
+type connProfSorter struct {
+	cps []*ConnProfile
+}
+
+func (s connProfSorter) Len() int {
+	return len(s.cps)
+}
+func (s connProfSorter) Swap(i, j int) {
+	s.cps[i], s.cps[j] = s.cps[j], s.cps[i]
+}
+func (s connProfSorter) Less(i, j int) bool {
+	return s.cps[i].Name() < s.cps[j].Name()
+}
+
+func SortConnProfs(cps []*ConnProfile) []*ConnProfile {
+	sorter := connProfSorter{
+		cps: make([]*ConnProfile, 0, len(cps)),
+	}
+
+	for _, p := range cps {
+		sorter.cps = append(sorter.cps, p)
+	}
+
+	sort.Sort(sorter)
+	return sorter.cps
+}
+
 func (cpm *ConnProfileMgr) GetConnProfileList() ([]*ConnProfile, error) {
 	log.Debugf("Getting list of connection profiles")
 
@@ -106,7 +134,7 @@ func (cpm *ConnProfileMgr) GetConnProfileList() ([]*ConnProfile, error) {
 		cpList = append(cpList, p)
 	}
 
-	return cpList, nil
+	return SortConnProfs(cpList), nil
 }
 
 func (cpm *ConnProfileMgr) save() error {