func search(term, homedir string) (map[string]*model.Chartfile, error) { dirs, err := filepath.Glob(filepath.Join(homedir, CacheChartPath, "*")) if err != nil { return nil, fmt.Errorf("No results found. %s", err) } else if len(dirs) == 0 { return nil, errors.New("No results found.") } charts := make(map[string]*model.Chartfile) r, _ := regexp.Compile(term) for _, dir := range dirs { chart, err := model.LoadChartfile(filepath.Join(dir, "Chart.yaml")) if err != nil { log.Info("\t%s - UNKNOWN", filepath.Base(dir)) continue } else if r.MatchString(chart.Name) || r.MatchString(chart.Description) { charts[dir] = chart } } return charts, nil }
// dependencyCache builds a map of chart and Chartfile. func dependencyCache(chartdir string) (map[string]*model.Chartfile, error) { cache := map[string]*model.Chartfile{} dir, err := os.Open(chartdir) if err != nil { return cache, err } defer dir.Close() fis, err := dir.Readdir(0) if err != nil { return cache, err } for _, fi := range fis { if !fi.IsDir() { continue } cf, err := model.LoadChartfile(filepath.Join(chartdir, fi.Name(), "Chart.yaml")) if err != nil { // If the chartfile does not load, we ignore it. continue } cache[fi.Name()] = cf } return cache, nil }
// Fetch gets a chart from the source repo and copies to the workdir. // // - chart is the source // - lname is the local name for that chart (chart-name); if blank, it is set to the chart. // - homedir is the home directory for the user // - ns is the namespace for this package. If blank, it is set to the DefaultNS. func Fetch(chart, lname, homedir string) { if lname == "" { lname = chart } fetch(chart, lname, homedir) cfile, err := model.LoadChartfile(filepath.Join(homedir, WorkspaceChartPath, chart, "Chart.yaml")) if err != nil { log.Die("Source is not a valid chart. Missing Chart.yaml: %s", err) } deps, err := dependency.Resolve(cfile, filepath.Join(homedir, WorkspaceChartPath)) if err != nil { log.Warn("Could not check dependencies: %s", err) return } if len(deps) > 0 { log.Warn("Unsatisfied dependencies:") for _, d := range deps { log.Msg("\t%s %s", d.Name, d.Version) } } PrintREADME(lname, homedir) }
// List lists all of the local charts. func List(homedir string) { md := filepath.Join(homedir, WorkspaceChartPath, "*") charts, err := filepath.Glob(md) if err != nil { log.Warn("Could not find any charts in %q: %s", md, err) } for _, c := range charts { cname := filepath.Base(c) if ch, err := model.LoadChartfile(filepath.Join(c, "Chart.yaml")); err == nil { log.Info("\t%s (%s %s) - %s", cname, ch.Name, ch.Version, ch.Description) continue } log.Info("\t%s (unknown)", cname) } }
func Info(chart, homedir string) { chartPath := filepath.Join(homedir, CacheChartPath, chart, "Chart.yaml") log.Info("%s", chartPath) chartModel, err := model.LoadChartfile(chartPath) if err != nil { log.Die("%s - UNKNOWN", chart) } log.Info("Chart: %s", chartModel.Name) log.Info("Description: %s", chartModel.Description) log.Info("Details: %s", chartModel.Details) log.Info("Version: %s", chartModel.Version) log.Info("Website: %s", chartModel.Home) log.Info("From: %s", chartPath) log.Info("Dependencies: %s", chartModel.Dependencies) }
func TestResolve(t *testing.T) { cf, err := model.LoadChartfile(filepath.Join(testInstalldir, "deptest/Chart.yaml")) if err != nil { t.Errorf("Could not load chartfile deptest/Chart.yaml: %s", err) } missed, err := Resolve(cf, testInstalldir) if err != nil { t.Errorf("could not resolve deps in %s: %s", testInstalldir, err) } if len(missed) != 2 { t.Fatalf("Expected dep3 and honkIfYouLoveDucks to be returned") } if missed[0].Name != "dep3" { t.Errorf("Expected dep3 in slot 0. Got %s", missed[0].Name) } if missed[1].Name != "honkIfYouLoveDucks" { t.Errorf("Expected honkIfYouLoveDucks in slot 1. Got %s", missed[1].Name) } }
// Search looks for packages with 'term' in their name. func Search(term, homedir string) { dirs, err := search(term, homedir) if err != nil { log.Die(err.Error()) } log.Info("\n=================") log.Info("Available Charts") log.Info("=================\n") for _, d := range dirs { y, err := model.LoadChartfile(filepath.Join(d, "Chart.yaml")) if err != nil { log.Info("\t%s - UNKNOWN", filepath.Base(d)) continue } log.Info("\t%s (%s %s) - %s", filepath.Base(d), y.Name, y.Version, y.Description) } log.Info("") }