Skip to content

Commit

Permalink
Improve cache list command
Browse files Browse the repository at this point in the history
  • Loading branch information
kairen authored and dlorenc committed Dec 8, 2017
1 parent 37bc507 commit 777b446
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions cmd/minikube/cmd/cache_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
)

const cacheListFormat = "- {{.CacheImageName}}\n"
var cacheListFormat string

type CacheListTemplate struct {
CacheImageName string
CacheImage string
}

// listCacheCmd represents the cache list command
Expand All @@ -52,17 +52,20 @@ var listCacheCmd = &cobra.Command{
}

func init() {
listCacheCmd.Flags().StringVar(&cacheListFormat, "format", constants.DefaultCacheListFormat,
`Go template format string for the cache list output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
For the list of accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd#CacheListTemplate`)
cacheCmd.AddCommand(listCacheCmd)
}

func cacheList(images map[string]interface{}) error {
for imageName := range images {
func cacheList(images []string) error {
for _, image := range images {
tmpl, err := template.New("list").Parse(cacheListFormat)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating list template: %s\n", err)
os.Exit(1)
}
listTmplt := CacheListTemplate{imageName}
listTmplt := CacheListTemplate{image}
err = tmpl.Execute(os.Stdout, listTmplt)
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing list template: %s\n", err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ func configurableFields() string {
}

// ListConfigMap list entries from config file
func ListConfigMap(name string) (map[string]interface{}, error) {
func ListConfigMap(name string) ([]string, error) {
configFile, err := config.ReadConfig()
if err != nil {
return nil, err
}
newImages := make(map[string]interface{})
var images []string
if values, ok := configFile[name].(map[string]interface{}); ok {
for key := range values {
newImages[key] = nil
images = append(images, key)
}
}
return newImages, nil
return images, nil
}

// AddToConfigMap adds entries to a map in the config file
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const (
"cluster: {{.ClusterStatus}}\n" + "kubectl: {{.KubeconfigStatus}}\n"
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
DefaultCacheListFormat = "{{.CacheImage}}\n"
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
KubernetesVersionGCSURL = "https://storage.googleapis.com/minikube/k8s_releases.json"
DefaultWait = 20
Expand Down

0 comments on commit 777b446

Please sign in to comment.