Skip to content

Commit 777b446

Browse files
kairendlorenc
kairen
authored andcommitted
Improve cache list command
1 parent 37bc507 commit 777b446

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

cmd/minikube/cmd/cache_list.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"k8s.io/minikube/pkg/minikube/constants"
2727
)
2828

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

3131
type CacheListTemplate struct {
32-
CacheImageName string
32+
CacheImage string
3333
}
3434

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

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

58-
func cacheList(images map[string]interface{}) error {
59-
for imageName := range images {
61+
func cacheList(images []string) error {
62+
for _, image := range images {
6063
tmpl, err := template.New("list").Parse(cacheListFormat)
6164
if err != nil {
6265
fmt.Fprintf(os.Stderr, "Error creating list template: %s\n", err)
6366
os.Exit(1)
6467
}
65-
listTmplt := CacheListTemplate{imageName}
68+
listTmplt := CacheListTemplate{image}
6669
err = tmpl.Execute(os.Stdout, listTmplt)
6770
if err != nil {
6871
fmt.Fprintf(os.Stderr, "Error executing list template: %s\n", err)

cmd/minikube/cmd/config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,18 @@ func configurableFields() string {
220220
}
221221

222222
// ListConfigMap list entries from config file
223-
func ListConfigMap(name string) (map[string]interface{}, error) {
223+
func ListConfigMap(name string) ([]string, error) {
224224
configFile, err := config.ReadConfig()
225225
if err != nil {
226226
return nil, err
227227
}
228-
newImages := make(map[string]interface{})
228+
var images []string
229229
if values, ok := configFile[name].(map[string]interface{}); ok {
230230
for key := range values {
231-
newImages[key] = nil
231+
images = append(images, key)
232232
}
233233
}
234-
return newImages, nil
234+
return images, nil
235235
}
236236

237237
// AddToConfigMap adds entries to a map in the config file

pkg/minikube/constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const (
9696
"cluster: {{.ClusterStatus}}\n" + "kubectl: {{.KubeconfigStatus}}\n"
9797
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
9898
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
99+
DefaultCacheListFormat = "{{.CacheImage}}\n"
99100
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
100101
KubernetesVersionGCSURL = "https://storage.googleapis.com/minikube/k8s_releases.json"
101102
DefaultWait = 20

0 commit comments

Comments
 (0)