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 2015/11/21 00:17:22 UTC
incubator-mynewt-newt git commit: Sort output of 'target show' by
target name.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/master 319767d6d -> af00aad0f
Sort output of 'target show' by target name.
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/af00aad0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/af00aad0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/af00aad0
Branch: refs/heads/master
Commit: af00aad0fc3628e2789465d9253c06c57cfbdd7e
Parents: 319767d
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Nov 20 15:17:06 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Nov 20 15:17:06 2015 -0800
----------------------------------------------------------------------
newt.go | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/af00aad0/newt.go
----------------------------------------------------------------------
diff --git a/newt.go b/newt.go
index 0da2aa1..5331039 100644
--- a/newt.go
+++ b/newt.go
@@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"regexp"
+ "sort"
"strings"
)
@@ -126,6 +127,13 @@ func targetUnsetCmd(cmd *cobra.Command, args []string) {
"Target %s successfully unset %s\n", args[0], args[1])
}
+// Type for sorting an array of target pointers alphabetically by name.
+type ByName []*cli.Target
+
+func (a ByName) Len() int { return len(a) }
+func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+func (a ByName) Less(i, j int) bool { return a[i].Vars["name"] < a[j].Vars["name"] }
+
func targetShowCmd(cmd *cobra.Command, args []string) {
dispSect := ""
if len(args) == 1 {
@@ -137,6 +145,8 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, err)
}
+ sort.Sort(ByName(targets))
+
for _, target := range targets {
if dispSect == "" || dispSect == target.Vars["name"] {
cli.StatusMessage(cli.VERBOSITY_QUIET, target.Vars["name"]+"\n")