You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/03/06 21:17:01 UTC

[27/50] [abbrv] incubator-mynewt-newt git commit: newt; move targetSyscfgKVxxx() routines to be inside syscfg package.

newt; move targetSyscfgKVxxx() routines to be inside syscfg package.


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/1a50286f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1a50286f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1a50286f

Branch: refs/heads/master
Commit: 1a50286fabdf32c92d6887be312f35fe30b98682
Parents: 2f4975d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Feb 28 16:58:21 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Feb 28 16:58:21 2017 -0800

----------------------------------------------------------------------
 newt/cli/target_cmds.go | 54 ++------------------------------------------
 newt/syscfg/syscfg.go   | 50 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1a50286f/newt/cli/target_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 8888847..a6ea7df 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -121,7 +121,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
 		}
 
 		// A few variables come from the base package rather than the target.
-		kvPairs["syscfg"] = targetSyscfgKVToStr(
+		kvPairs["syscfg"] = syscfg.KeyValueToStr(
 			target.Package().SyscfgV.GetStringMapString("syscfg.vals"))
 		kvPairs["cflags"] = pkgVarSliceString(target.Package(), "pkg.cflags")
 		kvPairs["lflags"] = pkgVarSliceString(target.Package(), "pkg.lflags")
@@ -142,56 +142,6 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
 	}
 }
 
-func targetSyscfgKVFromStr(str string) (map[string]string, error) {
-	vals := map[string]string{}
-
-	if strings.TrimSpace(str) == "" {
-		return vals, nil
-	}
-
-	// Separate syscfg vals are delimited by ':'.
-	fields := strings.Split(str, ":")
-
-	// Key-value pairs are delimited by '='.  If no '=' is present, assume the
-	// string is the key name and the value is 1.
-	for _, f := range fields {
-		if _, err := util.AtoiNoOct(f); err == nil {
-			return nil, util.FmtNewtError(
-				"Invalid setting name \"%s\"; must not be a number", f)
-		}
-
-		kv := strings.SplitN(f, "=", 2)
-		switch len(kv) {
-		case 1:
-			vals[f] = "1"
-		case 2:
-			vals[kv[0]] = kv[1]
-		}
-	}
-
-	return vals, nil
-}
-
-func targetSyscfgKVToStr(syscfgKv map[string]string) string {
-	str := ""
-
-	names := make([]string, 0, len(syscfgKv))
-	for k, _ := range syscfgKv {
-		names = append(names, k)
-	}
-	sort.Strings(names)
-
-	for i, name := range names {
-		if i != 0 {
-			str += ":"
-		}
-
-		str += fmt.Sprintf("%s=%s", name, syscfgKv[name])
-	}
-
-	return str
-}
-
 func targetSetCmd(cmd *cobra.Command, args []string) {
 	if len(args) < 2 {
 		NewtUsage(cmd,
@@ -234,7 +184,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 		// instead of the target.
 		if kv[0] == "target.syscfg" {
 			t.Package().SyscfgV = viper.New()
-			kv, err := targetSyscfgKVFromStr(kv[1])
+			kv, err := syscfg.KeyValueFromStr(kv[1])
 			if err != nil {
 				NewtUsage(cmd, err)
 			}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1a50286f/newt/syscfg/syscfg.go
----------------------------------------------------------------------
diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index f5cef0e..cac298e 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -993,3 +993,53 @@ func EnsureWritten(cfg Cfg, includeDir string) error {
 
 	return nil
 }
+
+func KeyValueFromStr(str string) (map[string]string, error) {
+	vals := map[string]string{}
+
+	if strings.TrimSpace(str) == "" {
+		return vals, nil
+	}
+
+	// Separate syscfg vals are delimited by ':'.
+	fields := strings.Split(str, ":")
+
+	// Key-value pairs are delimited by '='.  If no '=' is present, assume the
+	// string is the key name and the value is 1.
+	for _, f := range fields {
+		if _, err := util.AtoiNoOct(f); err == nil {
+			return nil, util.FmtNewtError(
+				"Invalid setting name \"%s\"; must not be a number", f)
+		}
+
+		kv := strings.SplitN(f, "=", 2)
+		switch len(kv) {
+		case 1:
+			vals[f] = "1"
+		case 2:
+			vals[kv[0]] = kv[1]
+		}
+	}
+
+	return vals, nil
+}
+
+func KeyValueToStr(syscfgKv map[string]string) string {
+	str := ""
+
+	names := make([]string, 0, len(syscfgKv))
+	for k, _ := range syscfgKv {
+		names = append(names, k)
+	}
+	sort.Strings(names)
+
+	for i, name := range names {
+		if i != 0 {
+			str += ":"
+		}
+
+		str += fmt.Sprintf("%s=%s", name, syscfgKv[name])
+	}
+
+	return str
+}