// GPMGodepsGit reads a Godeps-Git file for gpm-git. func GPMGodepsGit(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { dir := cookoo.GetString("dir", "", p) path := filepath.Join(dir, "Godeps-Git") if _, err := os.Stat(path); err != nil { return []*yaml.Dependency{}, nil } Info("Found Godeps-Git file.\n") buf := []*yaml.Dependency{} file, err := os.Open(path) if err != nil { return buf, err } scanner := bufio.NewScanner(file) for scanner.Scan() { parts, ok := parseGodepsLine(scanner.Text()) if ok { dep := &yaml.Dependency{Name: parts[1], Repository: parts[0]} if len(parts) > 2 { dep.Reference = parts[2] } buf = append(buf, dep) } } if err := scanner.Err(); err != nil { Warn("Scan failed: %s\n", err) return buf, err } return buf, nil }
// Template is a template-based text formatter. // // This uses the core `text/template` to process a given string template. // // Params // - template (string): A template string. // - template.Context (bool): If true, the context will be placed into the // template renderer as 'Cxt', and can be used as `{{.Cxt.Foo}}`. False // by default. // - ... (interface{}): Values passed into the template. // // Conventionally, template variables should start with an initial capital. // // Returns a formatted string. func Template(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { format := cookoo.GetString("template", "", p) withCxt := cookoo.GetBool("template.Context", false, p) name := fmt.Sprintf("%x", md5.Sum([]byte(format))) //c.Logf("debug", "Template %s is '%s'\n", name, format) tpl, err := template.New(name).Parse(format) if err != nil { return "", err } data := p.AsMap() if withCxt { //c.Logf("debug", "Adding context.") data["Cxt"] = c.AsMap() } var out bytes.Buffer if err := tpl.Execute(&out, data); err != nil { return "", err } return out.String(), nil }
// GbManifest // // Params: // - dir (string): The directory where the manifest file is located. // Returns: // func GbManifest(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { dir := cookoo.GetString("dir", ".", p) return parseGbManifest(dir) }
func HasGbManifest(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { dir := cookoo.GetString("dir", "", p) path := filepath.Join(dir, "vendor/manifest") _, err := os.Stat(path) return err == nil, nil }
// GPMGodeps parses a GPM-flavored Godeps file. // // Params // - dir (string): Directory root. // // Returns an []*yaml.Dependency func GPMGodeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { dir := cookoo.GetString("dir", "", p) return parseGPMGodeps(dir) }
// HasGPMGodeps indicates whether a Godeps file exists. func HasGPMGodeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { dir := cookoo.GetString("dir", "", p) path := filepath.Join(dir, "Godeps") _, err := os.Stat(path) return err == nil, nil }
// Println prints a string to standard output, and appends a newline. // // Also see web.Flush. // // Params: // - content (string): The string to print. func Println(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { msg := cookoo.GetString("content", "", p) fmt.Println(msg) return msg, nil }