mirror of https://github.com/helm/helm.git
ref(repo): fix style errors in cmd/helm & pkg/repo
This commit is contained in:
parent
39a9eab114
commit
ae720981d3
|
@ -17,10 +17,10 @@ var fetchCmd = &cobra.Command{
|
|||
Use: "fetch",
|
||||
Short: "Download a chart from a repository and unpack it in local directory.",
|
||||
Long: "",
|
||||
RunE: Fetch,
|
||||
RunE: fetch,
|
||||
}
|
||||
|
||||
func Fetch(cmd *cobra.Command, args []string) error {
|
||||
func fetch(cmd *cobra.Command, args []string) error {
|
||||
// parse args
|
||||
// get download url
|
||||
// call download url
|
||||
|
|
|
@ -81,7 +81,7 @@ func buildKubectlRunner(kubectlPath string) kubectl.Runner {
|
|||
//
|
||||
// If $HELM_HOME does not exist, this function will create it.
|
||||
func ensureHome(home string) error {
|
||||
configDirectories := []string{home, CacheDirectory(home), LocalDirectory(home)}
|
||||
configDirectories := []string{home, cacheDirectory(home), localDirectory(home)}
|
||||
|
||||
for _, p := range configDirectories {
|
||||
if fi, err := os.Stat(p); err != nil {
|
||||
|
@ -104,7 +104,7 @@ func ensureHome(home string) error {
|
|||
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 {
|
||||
fmt.Printf("Creating %s \n", localCacheFile)
|
||||
_, err := os.Create(localCacheFile)
|
||||
|
@ -113,9 +113,9 @@ func ensureHome(home string) error {
|
|||
}
|
||||
|
||||
//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() {
|
||||
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
|
||||
}
|
||||
|
@ -128,10 +128,10 @@ func repositoriesFile(home string) string {
|
|||
return filepath.Join(home, repositoriesPath)
|
||||
}
|
||||
|
||||
func LocalDirectory(home string) string {
|
||||
func localDirectory(home string) string {
|
||||
return filepath.Join(home, localPath)
|
||||
}
|
||||
|
||||
func LocalDirCacheFile(home string) string {
|
||||
func localDirCacheFile(home string) string {
|
||||
return filepath.Join(home, localCacheFilePath)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ func TestEnsureHome(t *testing.T) {
|
|||
t.Errorf("%s", err)
|
||||
}
|
||||
|
||||
dirs := []string{home, CacheDirectory(home), LocalDirectory(home)}
|
||||
dirs := []string{home, cacheDirectory(home), localDirectory(home)}
|
||||
for _, dir := range dirs {
|
||||
if fi, err := os.Stat(dir); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
|
|
|
@ -56,7 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Save to $HELM_HOME/local directory.
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ var searchCmd = &cobra.Command{
|
|||
Use: "search [CHART]",
|
||||
Short: "Search for charts",
|
||||
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 {
|
||||
return errors.New("This command needs at least one argument")
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func Search(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
func searchCacheForPattern(name string) ([]string, error) {
|
||||
dir := CacheDirectory(os.ExpandEnv(helmHome))
|
||||
dir := cacheDirectory(os.ExpandEnv(helmHome))
|
||||
fileList := []string{}
|
||||
filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
|
||||
if !f.IsDir() {
|
||||
|
|
|
@ -20,9 +20,9 @@ var serveCmd = &cobra.Command{
|
|||
Use: "serve",
|
||||
Short: "Start a local http web server",
|
||||
Long: serveDesc,
|
||||
Run: ServeLocal,
|
||||
Run: serve,
|
||||
}
|
||||
|
||||
func ServeLocal(cmd *cobra.Command, args []string) {
|
||||
repo.StartLocalRepo(LocalDirectory(os.ExpandEnv(helmHome)))
|
||||
func serve(cmd *cobra.Command, args []string) {
|
||||
repo.StartLocalRepo(localDirectory(os.ExpandEnv(helmHome)))
|
||||
}
|
||||
|
|
|
@ -13,15 +13,18 @@ import (
|
|||
|
||||
var localRepoPath string
|
||||
|
||||
// CacheFile represents the cache file in a chart repository
|
||||
type CacheFile struct {
|
||||
Entries map[string]*ChartRef
|
||||
}
|
||||
|
||||
// ChartRef represents a chart entry in the CacheFile
|
||||
type ChartRef struct {
|
||||
Name string
|
||||
Url string
|
||||
URL string
|
||||
}
|
||||
|
||||
// StartLocalRepo starts a web server and serves files from the given path
|
||||
func StartLocalRepo(path string) {
|
||||
fmt.Println("Now serving you on localhost:8879...")
|
||||
localRepoPath = path
|
||||
|
@ -49,6 +52,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) {
|
|||
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 {
|
||||
name, err := chart.Save(ch, path)
|
||||
if err != nil {
|
||||
|
@ -62,6 +66,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCacheFile takes a file at the given path and returns a CacheFile object
|
||||
func LoadCacheFile(path string) (*CacheFile, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
|
@ -77,6 +82,7 @@ func LoadCacheFile(path string) (*CacheFile, error) {
|
|||
return &y, nil
|
||||
}
|
||||
|
||||
// ReindexCacheFile adds an entry to the cache file at the given path
|
||||
func ReindexCacheFile(ch *chart.Chart, path string) error {
|
||||
name := ch.Chartfile().Name + "-" + ch.Chartfile().Version
|
||||
y, err := LoadCacheFile(path)
|
||||
|
@ -93,7 +99,7 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|||
if !found {
|
||||
url := "localhost:8879/charts/" + name + ".tgz"
|
||||
|
||||
out, err := y.InsertChartEntry(name, url)
|
||||
out, err := y.insertChartEntry(name, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -102,6 +108,8 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalYAML unmarshals the cache file
|
||||
func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var refs map[string]*ChartRef
|
||||
if err := unmarshal(&refs); err != nil {
|
||||
|
@ -113,13 +121,13 @@ func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (cache *CacheFile) InsertChartEntry(name string, url string) ([]byte, error) {
|
||||
if cache.Entries == nil {
|
||||
cache.Entries = make(map[string]*ChartRef)
|
||||
func (c *CacheFile) insertChartEntry(name string, url string) ([]byte, error) {
|
||||
if c.Entries == nil {
|
||||
c.Entries = make(map[string]*ChartRef)
|
||||
}
|
||||
entry := ChartRef{Name: name, Url: url}
|
||||
cache.Entries[name] = &entry
|
||||
out, err := yaml.Marshal(&cache.Entries)
|
||||
entry := ChartRef{Name: name, URL: url}
|
||||
c.Entries[name] = &entry
|
||||
out, err := yaml.Marshal(&c.Entries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue