예제 #1
0
파일: importer.go 프로젝트: Zuozuohao/glide
// Import tries to import configuration from Glide, Godep, GPM, GB and gom.
func (d *DefaultImporter) Import(path string) (bool, []*cfg.Dependency, error) {

	// Try importing from Glide first.
	p := filepath.Join(path, "glide.yaml")
	if _, err := os.Stat(p); err == nil {
		// We found glide configuration.
		yml, err := ioutil.ReadFile(p)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		conf, err := cfg.ConfigFromYaml(yml)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		return true, conf.Imports, nil
	}

	// Try importing from Godep
	if godep.Has(path) {
		deps, err := godep.Parse(path)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		return true, deps, nil
	}

	// Try importing from GPM
	if gpm.Has(path) {
		deps, err := gpm.Parse(path)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		return true, deps, nil
	}

	// Try importin from GB
	if gb.Has(path) {
		deps, err := gb.Parse(path)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		return true, deps, nil
	}

	// Try importing from gom
	if gom.Has(path) {
		deps, err := gom.Parse(path)
		if err != nil {
			return false, []*cfg.Dependency{}, err
		}
		return true, deps, nil
	}

	// When none are found.
	return false, []*cfg.Dependency{}, nil
}
예제 #2
0
// ImportGPM imports a GPM file.
func ImportGPM(dest string) {
	base := "."
	config := EnsureConfig()
	if !gpm.Has(base) {
		msg.Die("No GPM Godeps file found.")
	}
	deps, err := gpm.Parse(base)
	if err != nil {
		msg.Die("Failed to extract GPM Godeps file: %s", err)
	}
	appendImports(deps, config)
	writeConfigToFileOrStdout(config, dest)
}