Commit ae720981 authored by Michelle Noorali's avatar Michelle Noorali

ref(repo): fix style errors in cmd/helm & pkg/repo

parent 39a9eab1
...@@ -17,10 +17,10 @@ var fetchCmd = &cobra.Command{ ...@@ -17,10 +17,10 @@ var fetchCmd = &cobra.Command{
Use: "fetch", Use: "fetch",
Short: "Download a chart from a repository and unpack it in local directory.", Short: "Download a chart from a repository and unpack it in local directory.",
Long: "", Long: "",
RunE: Fetch, RunE: fetch,
} }
func Fetch(cmd *cobra.Command, args []string) error { func fetch(cmd *cobra.Command, args []string) error {
// parse args // parse args
// get download url // get download url
// call download url // call download url
......
...@@ -81,7 +81,7 @@ func buildKubectlRunner(kubectlPath string) kubectl.Runner { ...@@ -81,7 +81,7 @@ func buildKubectlRunner(kubectlPath string) kubectl.Runner {
// //
// If $HELM_HOME does not exist, this function will create it. // If $HELM_HOME does not exist, this function will create it.
func ensureHome(home string) error { func ensureHome(home string) error {
configDirectories := []string{home, CacheDirectory(home), LocalDirectory(home)} configDirectories := []string{home, cacheDirectory(home), localDirectory(home)}
for _, p := range configDirectories { for _, p := range configDirectories {
if fi, err := os.Stat(p); err != nil { if fi, err := os.Stat(p); err != nil {
...@@ -104,7 +104,7 @@ func ensureHome(home string) error { ...@@ -104,7 +104,7 @@ func ensureHome(home string) error {
return fmt.Errorf("%s must be a file, not a directory", repoPath) return fmt.Errorf("%s must be a file, not a directory", repoPath)
} }
localCacheFile := LocalDirCacheFile(home) localCacheFile := localDirCacheFile(home)
if fi, err := os.Stat(localCacheFile); err != nil { if fi, err := os.Stat(localCacheFile); err != nil {
fmt.Printf("Creating %s \n", localCacheFile) fmt.Printf("Creating %s \n", localCacheFile)
_, err := os.Create(localCacheFile) _, err := os.Create(localCacheFile)
...@@ -113,9 +113,9 @@ func ensureHome(home string) error { ...@@ -113,9 +113,9 @@ func ensureHome(home string) error {
} }
//TODO: take this out and replace with helm update functionality //TODO: take this out and replace with helm update functionality
os.Symlink(localCacheFile, CacheDirectory(home)+"/local-cache.yaml") os.Symlink(localCacheFile, cacheDirectory(home)+"/local-cache.yaml")
} else if fi.IsDir() { } else if fi.IsDir() {
return fmt.Errorf("%s must be a file, not a directory.", repoPath) return fmt.Errorf("%s must be a file, not a directory", repoPath)
} }
return nil return nil
} }
...@@ -128,10 +128,10 @@ func repositoriesFile(home string) string { ...@@ -128,10 +128,10 @@ func repositoriesFile(home string) string {
return filepath.Join(home, repositoriesPath) return filepath.Join(home, repositoriesPath)
} }
func LocalDirectory(home string) string { func localDirectory(home string) string {
return filepath.Join(home, localPath) return filepath.Join(home, localPath)
} }
func LocalDirCacheFile(home string) string { func localDirCacheFile(home string) string {
return filepath.Join(home, localCacheFilePath) return filepath.Join(home, localCacheFilePath)
} }
...@@ -12,7 +12,7 @@ func TestEnsureHome(t *testing.T) { ...@@ -12,7 +12,7 @@ func TestEnsureHome(t *testing.T) {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
dirs := []string{home, CacheDirectory(home), LocalDirectory(home)} dirs := []string{home, cacheDirectory(home), localDirectory(home)}
for _, dir := range dirs { for _, dir := range dirs {
if fi, err := os.Stat(dir); err != nil { if fi, err := os.Stat(dir); err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
......
...@@ -56,7 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error { ...@@ -56,7 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
// Save to $HELM_HOME/local directory. // Save to $HELM_HOME/local directory.
if save { if save {
if err := repo.AddChartToLocalRepo(ch, LocalDirectory(os.ExpandEnv(helmHome))); err != nil { if err := repo.AddChartToLocalRepo(ch, localDirectory(os.ExpandEnv(helmHome))); err != nil {
return err return err
} }
} }
......
...@@ -19,10 +19,10 @@ var searchCmd = &cobra.Command{ ...@@ -19,10 +19,10 @@ var searchCmd = &cobra.Command{
Use: "search [CHART]", Use: "search [CHART]",
Short: "Search for charts", Short: "Search for charts",
Long: "", //TODO: add search command description Long: "", //TODO: add search command description
RunE: Search, RunE: search,
} }
func Search(cmd *cobra.Command, args []string) error { func search(cmd *cobra.Command, args []string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("This command needs at least one argument") return errors.New("This command needs at least one argument")
} }
...@@ -39,7 +39,7 @@ func Search(cmd *cobra.Command, args []string) error { ...@@ -39,7 +39,7 @@ func Search(cmd *cobra.Command, args []string) error {
} }
func searchCacheForPattern(name string) ([]string, error) { func searchCacheForPattern(name string) ([]string, error) {
dir := CacheDirectory(os.ExpandEnv(helmHome)) dir := cacheDirectory(os.ExpandEnv(helmHome))
fileList := []string{} fileList := []string{}
filepath.Walk(dir, func(path string, f os.FileInfo, err error) error { filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() { if !f.IsDir() {
......
...@@ -20,9 +20,9 @@ var serveCmd = &cobra.Command{ ...@@ -20,9 +20,9 @@ var serveCmd = &cobra.Command{
Use: "serve", Use: "serve",
Short: "Start a local http web server", Short: "Start a local http web server",
Long: serveDesc, Long: serveDesc,
Run: ServeLocal, Run: serve,
} }
func ServeLocal(cmd *cobra.Command, args []string) { func serve(cmd *cobra.Command, args []string) {
repo.StartLocalRepo(LocalDirectory(os.ExpandEnv(helmHome))) repo.StartLocalRepo(localDirectory(os.ExpandEnv(helmHome)))
} }
...@@ -13,15 +13,18 @@ import ( ...@@ -13,15 +13,18 @@ import (
var localRepoPath string var localRepoPath string
// CacheFile represents the cache file in a chart repository
type CacheFile struct { type CacheFile struct {
Entries map[string]*ChartRef Entries map[string]*ChartRef
} }
// ChartRef represents a chart entry in the CacheFile
type ChartRef struct { type ChartRef struct {
Name string Name string
Url string URL string
} }
// StartLocalRepo starts a web server and serves files from the given path
func StartLocalRepo(path string) { func StartLocalRepo(path string) {
fmt.Println("Now serving you on localhost:8879...") fmt.Println("Now serving you on localhost:8879...")
localRepoPath = path localRepoPath = path
...@@ -49,6 +52,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) { ...@@ -49,6 +52,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) {
http.ServeFile(w, r, filepath.Join(localRepoPath, file)) http.ServeFile(w, r, filepath.Join(localRepoPath, file))
} }
// AddChartToLocalRepo saves a chart in the given path and then reindexes the cache file
func AddChartToLocalRepo(ch *chart.Chart, path string) error { func AddChartToLocalRepo(ch *chart.Chart, path string) error {
name, err := chart.Save(ch, path) name, err := chart.Save(ch, path)
if err != nil { if err != nil {
...@@ -62,6 +66,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error { ...@@ -62,6 +66,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error {
return nil return nil
} }
// LoadCacheFile takes a file at the given path and returns a CacheFile object
func LoadCacheFile(path string) (*CacheFile, error) { func LoadCacheFile(path string) (*CacheFile, error) {
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
...@@ -77,6 +82,7 @@ func LoadCacheFile(path string) (*CacheFile, error) { ...@@ -77,6 +82,7 @@ func LoadCacheFile(path string) (*CacheFile, error) {
return &y, nil return &y, nil
} }
// ReindexCacheFile adds an entry to the cache file at the given path
func ReindexCacheFile(ch *chart.Chart, path string) error { func ReindexCacheFile(ch *chart.Chart, path string) error {
name := ch.Chartfile().Name + "-" + ch.Chartfile().Version name := ch.Chartfile().Name + "-" + ch.Chartfile().Version
y, err := LoadCacheFile(path) y, err := LoadCacheFile(path)
...@@ -93,7 +99,7 @@ func ReindexCacheFile(ch *chart.Chart, path string) error { ...@@ -93,7 +99,7 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
if !found { if !found {
url := "localhost:8879/charts/" + name + ".tgz" url := "localhost:8879/charts/" + name + ".tgz"
out, err := y.InsertChartEntry(name, url) out, err := y.insertChartEntry(name, url)
if err != nil { if err != nil {
return err return err
} }
...@@ -102,6 +108,8 @@ func ReindexCacheFile(ch *chart.Chart, path string) error { ...@@ -102,6 +108,8 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
} }
return nil return nil
} }
// UnmarshalYAML unmarshals the cache file
func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error { func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
var refs map[string]*ChartRef var refs map[string]*ChartRef
if err := unmarshal(&refs); err != nil { if err := unmarshal(&refs); err != nil {
...@@ -113,13 +121,13 @@ func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -113,13 +121,13 @@ func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil return nil
} }
func (cache *CacheFile) InsertChartEntry(name string, url string) ([]byte, error) { func (c *CacheFile) insertChartEntry(name string, url string) ([]byte, error) {
if cache.Entries == nil { if c.Entries == nil {
cache.Entries = make(map[string]*ChartRef) c.Entries = make(map[string]*ChartRef)
} }
entry := ChartRef{Name: name, Url: url} entry := ChartRef{Name: name, URL: url}
cache.Entries[name] = &entry c.Entries[name] = &entry
out, err := yaml.Marshal(&cache.Entries) out, err := yaml.Marshal(&c.Entries)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment