func fetch(chartName, lname, homedir, chartpath string) { src := helm.CacheDirectory(homedir, chartpath, chartName) dest := helm.WorkspaceChartDirectory(homedir, lname) fi, err := os.Stat(src) if err != nil { log.Warn("Oops. Looks like there was an issue finding the chart, %s, in %s. Running `helmc update` to ensure you have the latest version of all Charts from Github...", lname, src) Update(homedir) fi, err = os.Stat(src) if err != nil { log.Die("Chart %s not found in %s", lname, src) } log.Info("Good news! Looks like that did the trick. Onwards and upwards!") } if !fi.IsDir() { log.Die("Malformed chart %s: Chart must be in a directory.", chartName) } if err := os.MkdirAll(dest, 0755); err != nil { log.Die("Could not create %q: %s", dest, err) } log.Debug("Fetching %s to %s", src, dest) if err := helm.CopyDir(src, dest); err != nil { log.Die("Failed copying %s to %s", src, dest) } if err := updateChartfile(src, dest, lname); err != nil { log.Die("Failed to update Chart.yaml: %s", err) } }
// Publish a chart from the workspace to the cache directory // // - chartName being published // - homeDir is the helm home directory for the user // - force publishing even if the chart directory already exists func Publish(chartName, homeDir, repo string, force bool) { if repo == "" { repo = "charts" } if !mustConfig(homeDir).Repos.Exists(repo) { log.Err("Repo %s does not exist", repo) log.Info("Available repositories") ListRepos(homeDir) return } src := helm.WorkspaceChartDirectory(homeDir, chartName) dst := helm.CacheDirectory(homeDir, repo, chartName) if _, err := os.Stat(dst); err == nil { if force != true { log.Info("chart already exists, use -f to force") return } } if err := helm.CopyDir(src, dst); err != nil { log.Die("failed to publish directory: %v", err) } }
// Search looks for packages with 'term' in their name. func Search(term, homedir string, regexp bool) { cfg := mustConfig(homedir) cdir := helm.CacheDirectory(homedir) i := search.NewIndex(cfg, cdir) res, err := i.Search(term, 5, regexp) if err != nil { log.Die("Failed to search: %s", err) } if len(res) == 0 { log.Err("No results found. Try using '--regexp'.") return } search.SortScore(res) for _, r := range res { c, _ := i.Chart(r.Name) log.Msg("%s - %s", r.Name, c.Description) } }
// Info prints information about a chart. // // - chartName to display // - homeDir is the helm home directory for the user // - format is a optional Go template func Info(chartName, homedir, format string) { r := mustConfig(homedir).Repos table, chartLocal := r.RepoChart(chartName) chartPath := helm.CacheDirectory(homedir, table, chartLocal, Chartfile) if format == "" { format = defaultInfoFormat } chart, err := chart.LoadChartfile(chartPath) if err != nil { log.Die("Could not find chart %s: %s", chartName, err.Error()) } tmpl, err := template.New("info").Parse(format) if err != nil { log.Die("%s", err) } if err = tmpl.Execute(log.Stdout, chart); err != nil { log.Die("%s", err) } }