Esempio n. 1
0
// 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
}
Esempio n. 2
0
File: yaml.go Progetto: rudle/glide
// ParseYamlString parses a YAML string. This is similar but different to
// ParseYaml that parses an external file.
//
// Params:
//	- yaml (string): YAML as a string.
//
// Returns:
//	- *cfg.Config: The configuration.
func ParseYamlString(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	yamlString := p.Get("yaml", "").(string)

	conf, err := cfg.ConfigFromYaml([]byte(yamlString))
	if err != nil {
		return nil, err
	}

	return conf, nil
}
Esempio n. 3
0
File: yaml.go Progetto: rudle/glide
// ParseYaml parses the glide.yaml format and returns a Configuration object.
//
// Params:
//	- filename (string): YAML filename as a string
//
// Returns:
//	- *cfg.Config: The configuration.
func ParseYaml(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	fname := p.Get("filename", "glide.yaml").(string)
	//conf := new(Config)
	yml, err := ioutil.ReadFile(fname)
	if err != nil {
		return nil, err
	}
	conf, err := cfg.ConfigFromYaml(yml)
	if err != nil {
		return nil, err
	}

	return conf, nil
}
Esempio n. 4
0
// EnsureConfig loads and returns a config file.
//
// Any error will cause an immediate exit, with an error printed to Stderr.
func EnsureConfig() *cfg.Config {
	yamlpath, err := gpath.Glide()
	if err != nil {
		msg.ExitCode(2)
		msg.Die("Failed to find %s file in directory tree: %s", gpath.GlideFile, err)
	}

	yml, err := ioutil.ReadFile(yamlpath)
	if err != nil {
		msg.ExitCode(2)
		msg.Die("Failed to load %s: %s", yamlpath, err)
	}
	conf, err := cfg.ConfigFromYaml(yml)
	if err != nil {
		msg.ExitCode(3)
		msg.Die("Failed to parse %s: %s", yamlpath, err)
	}

	b := filepath.Dir(yamlpath)
	buildContext, err := util.GetBuildContext()
	if err != nil {
		msg.Die("Failed to build an import context while ensuring config: %s", err)
	}
	cwd, err := os.Getwd()
	if err != nil {
		msg.Err("Unable to get the current working directory")
	} else {
		// Determining a package name requires a relative path
		b, err = filepath.Rel(b, cwd)
		if err == nil {
			name := buildContext.PackageName(b)
			if name != conf.Name {
				msg.Warn("The name listed in the config file (%s) does not match the current location (%s)", conf.Name, name)
			}
		} else {
			msg.Warn("Problem finding the config file path (%s) relative to the current directory (%s): %s", b, cwd, err)
		}
	}

	err = mirrors.Load()
	if err != nil {
		msg.Err("Unable to load mirrors: %s", err)
	}

	return conf
}
Esempio n. 5
0
File: ensure.go Progetto: gus/glide
// EnsureConfig loads and returns a config file.
//
// Any error will cause an immediate exit, with an error printed to Stderr.
func EnsureConfig() *cfg.Config {
	yamlpath, err := gpath.Glide()
	if err != nil {
		msg.ExitCode(2)
		msg.Die("Failed to find %s file in directory tree: %s", gpath.GlideFile, err)
	}

	yml, err := ioutil.ReadFile(yamlpath)
	if err != nil {
		msg.ExitCode(2)
		msg.Die("Failed to load %s: %s", yamlpath, err)
	}
	conf, err := cfg.ConfigFromYaml(yml)
	if err != nil {
		msg.ExitCode(3)
		msg.Die("Failed to parse %s: %s", yamlpath, err)
	}

	return conf
}
Esempio n. 6
0
func mergeGlide(dir, name string, f *flattening) ([]string, bool) {
	deps := f.deps
	vend := f.top
	gp := path.Join(dir, "glide.yaml")
	if _, err := os.Stat(gp); err != nil {
		return []string{}, false
	}

	yml, err := ioutil.ReadFile(gp)
	if err != nil {
		Warn("Found glide file %q, but can't read: %s", gp, err)
		return []string{}, false
	}

	conf, err := cfg.ConfigFromYaml(yml)
	if err != nil {
		Warn("Found glide file %q, but can't use it: %s", gp, err)
		return []string{}, false
	}

	Info("Found glide.yaml in %s", gp)

	return mergeDeps(deps, conf.Imports, vend, f), true
}