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-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new 3bac5ce  logcfg brief - sort entries by module ID
3bac5ce is described below

commit 3bac5ce9a6717bd1f2aff8b1e57563bc71605860
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Wed Apr 17 15:35:55 2019 -0700

    logcfg brief - sort entries by module ID
    
    Before this commit, the table was sorted lexicographically by log name.
    Sorting by module ID is more intuitive.
---
 newt/cli/target_cfg_cmds.go | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/newt/cli/target_cfg_cmds.go b/newt/cli/target_cfg_cmds.go
index 3636c86..f5af21b 100644
--- a/newt/cli/target_cfg_cmds.go
+++ b/newt/cli/target_cfg_cmds.go
@@ -410,24 +410,33 @@ func printLogCfgBrief(targetName string, lcfg 
logcfg.LCfg) {
        util.StatusMessage(util.VERBOSITY_DEFAULT, "Brief log config for %s:\n",
                targetName)
 
+       modules := make([]int, 0, len(lcfg.Logs))
+       modMap := make(map[int]logcfg.Log, len(lcfg.Logs))
+
+       // Keep track of the longest log name.  This allows the output to be
+       // properly aligned.
        longest := 6
-       logNames := make([]string, 0, len(lcfg.Logs))
-       for name, _ := range lcfg.Logs {
-               logNames = append(logNames, name)
+
+       // Map each module to its log, and build a sorted slice of module IDs.
+       for name, log := range lcfg.Logs {
+               modInt, _ := log.Module.IntVal()
+               modules = append(modules, modInt)
+               modMap[modInt] = log
                if len(name) > longest {
                        longest = len(name)
                }
        }
-       sort.Strings(logNames)
+       sort.Ints(modules)
 
+       // Print logs, sorted by module ID.
        colWidth := longest + 4
        util.StatusMessage(util.VERBOSITY_DEFAULT,
                "%*s | MODULE   | LEVEL\n", colWidth, "LOG")
        util.StatusMessage(util.VERBOSITY_DEFAULT,
                "%s-+----------+--------------\n",
                strings.Repeat("-", colWidth))
-       for _, logName := range logNames {
-               printLogCfgBriefOne(lcfg.Logs[logName], colWidth)
+       for _, module := range modules {
+               printLogCfgBriefOne(modMap[module], colWidth)
        }
 }
 

Reply via email to