Merge remote-tracking branch 'apache/master' into develop
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/48599c13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/48599c13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/48599c13 Branch: refs/heads/develop Commit: 48599c13235dfe62b6928849afd8d58a497cd900 Parents: 93cf30f c673365 Author: Christopher Collins <[email protected]> Authored: Thu Nov 10 11:38:28 2016 -0800 Committer: Christopher Collins <[email protected]> Committed: Thu Nov 10 11:38:28 2016 -0800 ---------------------------------------------------------------------- newt/newtutil/newtutil.go | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/48599c13/newt/newtutil/newtutil.go ---------------------------------------------------------------------- diff --cc newt/newtutil/newtutil.go index d7369d9,6e071f6..79b3cef --- a/newt/newtutil/newtutil.go +++ b/newt/newtutil/newtutil.go @@@ -33,52 -33,52 +33,129 @@@ import "mynewt.apache.org/newt/viper" ) -var NewtVersionStr string = "Apache Newt (incubating) version: 0.9.0" -var NewtBlinkyTag string = "mynewt_0_9_0_tag" +var NewtVersionStr string = "Apache Newt (incubating) version: 1.0.0-develop" +var NewtBlinkyTag string = "develop" + +const NEWTRC_DIR string = ".newt" +const REPOS_FILENAME string = "repos.yml" + +// Contains general newt settings read from $HOME/.newt +var newtrc *viper.Viper + +func readNewtrc() *viper.Viper { + usr, err := user.Current() + if err != nil { + log.Warn("Failed to obtain user name") + return viper.New() + } + + dir := usr.HomeDir + "/" + NEWTRC_DIR + v, err := util.ReadConfig(dir, strings.TrimSuffix(REPOS_FILENAME, ".yml")) + if err != nil { + log.Debugf("Failed to read %s/%s file", dir, REPOS_FILENAME) + return viper.New() + } + + return v +} + +func Newtrc() *viper.Viper { + if newtrc != nil { + return newtrc + } + + newtrc = readNewtrc() + return newtrc +} + +func GetSliceFeatures(v *viper.Viper, features map[string]bool, + key string) []interface{} { + + val := v.Get(key) + vals := []interface{}{val} + + // Process the features in alphabetical order to ensure consistent + // results across repeated runs. + var featureKeys []string + for feature, _ := range features { + featureKeys = append(featureKeys, feature) ++ } ++ sort.Strings(featureKeys) ++ ++ for _, feature := range featureKeys { ++ overwriteVal := v.Get(key + "." + feature + ".OVERWRITE") ++ if overwriteVal != nil { ++ return []interface{}{overwriteVal} ++ } ++ ++ appendVal := v.Get(key + "." + feature) ++ if appendVal != nil { ++ vals = append(vals, appendVal) ++ } ++ } ++ ++ return vals ++} ++ ++func GetStringMapFeatures(v *viper.Viper, features map[string]bool, ++ key string) map[string]interface{} { ++ ++ result := map[string]interface{}{} ++ ++ slice := GetSliceFeatures(v, features, key) ++ for _, itf := range slice { ++ sub := cast.ToStringMap(itf) ++ for k, v := range sub { ++ result[k] = v ++ } ++ } ++ ++ return result ++} + + const NEWTRC_DIR string = ".newt" + const REPOS_FILENAME string = "repos.yml" + + // Contains general newt settings read from $HOME/.newt + var newtrc *viper.Viper + + func readNewtrc() *viper.Viper { + usr, err := user.Current() + if err != nil { + log.Warn("Failed to obtain user name") + return viper.New() + } + + dir := usr.HomeDir + "/" + NEWTRC_DIR + v, err := util.ReadConfig(dir, strings.TrimSuffix(REPOS_FILENAME, ".yml")) + if err != nil { + log.Debugf("Failed to read %s/%s file", dir, REPOS_FILENAME) + return viper.New() + } + + return v + } + + func Newtrc() *viper.Viper { + if newtrc != nil { + return newtrc + } + + newtrc = readNewtrc() + return newtrc + } + + func GetSliceFeatures(v *viper.Viper, features map[string]bool, + key string) []interface{} { + + val := v.Get(key) + vals := []interface{}{val} + + // Process the features in alphabetical order to ensure consistent + // results across repeated runs. + var featureKeys []string + for feature, _ := range features { + featureKeys = append(featureKeys, feature) } sort.Strings(featureKeys)
