コード例 #1
0
ファイル: config_test.go プロジェクト: dyweb/Ayi
func (suite *GitConfigTestSuite) TestCast() {
	assert := assert.New(suite.T())
	hostsRaw := viper.Get("git.hosts")
	//fmt.Println(hostsRaw)
	hostsSlice := cast.ToSlice(hostsRaw)
	//fmt.Println(hostsSlice)

	for _, host := range hostsSlice {
		hostMap := cast.ToStringMap(host)
		name := cast.ToString(hostMap["name"])
		https := cast.ToBool(hostMap["https"])
		if name == "git.saber.io" {
			assert.Equal(false, https)
		}
	}
}
コード例 #2
0
ファイル: config.go プロジェクト: dyweb/Ayi
// ReadConfigFile read user defined hosts in .ayi.yml
func ReadConfigFile() {
	log.Debug("Read git section in config file")
	hostsMap = make(map[string]Host)
	hostsSlice := cast.ToSlice(viper.Get("git.hosts"))

	for _, h := range hostsSlice {
		m := cast.ToStringMap(h)
		_, exists := m["name"]
		if !exists {
			log.Warn("Skipp host without name")
			continue
		}

		// TODO: more attributes, the following is not working
		// - http port
		// - support ssh
		name := cast.ToString(m["name"])
		https := cast.ToBool(util.GetWithDefault(m, "https", true))
		port := cast.ToInt(util.GetWithDefault(m, "port", DefaultSSHPort))

		h := NewHost(name)
		h.SupportHTTPS = https
		h.SSHPort = port

		hosts = append(hosts, *h)
		// TODO: may add order to host
		hostsMap[name] = *h
	}

	// only merge default hosts that are not configed in config files
	for _, defaultHost := range DefaultHosts {
		_, exists := hostsMap[defaultHost.URL]
		if !exists {
			hosts = append(hosts, defaultHost)
			hostsMap[defaultHost.URL] = defaultHost
		}
	}
}
コード例 #3
0
ファイル: value.go プロジェクト: lcaballero/pregame
func (v *Value) ToSlice() []interface{} {
	return cast.ToSlice(v.values)
}
コード例 #4
0
ファイル: load.go プロジェクト: apache/incubator-mynewt-newt
func Load(basePkg *pkg.LocalPackage) (*MfgImage, error) {
	v, err := util.ReadConfig(basePkg.BasePath(),
		strings.TrimSuffix(MFG_YAML_FILENAME, ".yml"))
	if err != nil {
		return nil, err
	}

	mi := &MfgImage{
		basePkg: basePkg,
	}

	bootName := v.GetString("mfg.bootloader")
	if bootName == "" {
		return nil, mi.loadError("mfg.bootloader field required")
	}
	mi.boot, err = mi.loadTarget(bootName)
	if err != nil {
		return nil, err
	}

	imgNames := v.GetStringSlice("mfg.images")
	if imgNames != nil {
		for _, imgName := range imgNames {
			imgTarget, err := mi.loadTarget(imgName)
			if err != nil {
				return nil, err
			}

			mi.images = append(mi.images, imgTarget)
		}
	}

	if len(mi.images) > 2 {
		return nil, mi.loadError("too many images (%d); maximum is 2",
			len(mi.images))
	}

	itf := v.Get("mfg.raw")
	slice := cast.ToSlice(itf)
	if slice != nil {
		for i, entryItf := range slice {
			yamlEntry := cast.ToStringMapString(entryItf)
			entry, err := mi.loadRawEntry(i, yamlEntry)
			if err != nil {
				return nil, err
			}

			mi.rawEntries = append(mi.rawEntries, entry)
		}
	}

	proj := project.GetProject()

	bspLpkg, err := proj.ResolvePackage(mi.basePkg.Repo(),
		mi.boot.BspName)
	if err != nil {
		return nil, mi.loadError(
			"could not resolve boot loader BSP package: %s",
			mi.boot.BspName)
	}
	mi.bsp, err = pkg.NewBspPackage(bspLpkg)
	if err != nil {
		return nil, mi.loadError(err.Error())
	}

	for _, imgTarget := range mi.images {
		if len(mi.images) > 1 && imgTarget.LoaderName != "" {
			return nil, mi.loadError("only one image allowed in "+
				"split image mode (%s is a split build)", imgTarget.Name())
		}

		if imgTarget.Bsp() != mi.bsp.LocalPackage {
			return nil, mi.loadError(
				"image target \"%s\" specified conflicting BSP; "+
					"boot loader uses %s, image uses %s",
				imgTarget.Name(), mi.bsp.Name(), imgTarget.BspName)
		}
	}

	if err := mi.detectInvalidDevices(); err != nil {
		return nil, err
	}

	return mi, nil
}