Skip to content

Commit 9fb431d

Browse files
authored
Merge pull request #3485 from jandubois/templates-dir
Add dirnames.TemplatesDir() function
2 parents 1c8ac82 + d3ada98 commit 9fb431d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

pkg/store/dirnames/dirnames.go

+9
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ func LimaDisksDir() (string, error) {
6565
}
6666
return filepath.Join(limaDir, filenames.DisksDir), nil
6767
}
68+
69+
// LimaTemplatesDir returns the path of the templates directory, $LIMA_HOME/_templates.
70+
func LimaTemplatesDir() (string, error) {
71+
limaDir, err := LimaDir()
72+
if err != nil {
73+
return "", err
74+
}
75+
return filepath.Join(limaDir, filenames.TemplatesDir), nil
76+
}

pkg/store/filenames/filenames.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ package filenames
1010
// Instance names starting with an underscore are reserved for lima internal usage
1111

1212
const (
13-
ConfigDir = "_config"
14-
CacheDir = "_cache" // not yet implemented
15-
NetworksDir = "_networks" // network log files are stored here
16-
DisksDir = "_disks" // disks are stored here
13+
CacheDir = "_cache" // not yet implemented
14+
ConfigDir = "_config"
15+
DisksDir = "_disks" // disks are stored here
16+
NetworksDir = "_networks" // network log files are stored here
17+
TemplatesDir = "_templates" // user templates are stored here
1718
)
1819

1920
// Filenames used inside the ConfigDir

pkg/templatestore/templatestore.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ type Template struct {
2424
Location string `json:"location"`
2525
}
2626

27-
func TemplatesPaths() ([]string, error) {
27+
func templatesPaths() ([]string, error) {
2828
if tmplPath := os.Getenv("LIMA_TEMPLATES_PATH"); tmplPath != "" {
2929
return strings.Split(tmplPath, string(filepath.ListSeparator)), nil
3030
}
31-
limaDir, err := dirnames.LimaDir()
31+
limaTemplatesDir, err := dirnames.LimaTemplatesDir()
3232
if err != nil {
3333
return nil, err
3434
}
@@ -37,13 +37,13 @@ func TemplatesPaths() ([]string, error) {
3737
return nil, err
3838
}
3939
return []string{
40-
filepath.Join(limaDir, "_templates"),
40+
limaTemplatesDir,
4141
filepath.Join(shareDir, "templates"),
4242
}, nil
4343
}
4444

4545
func Read(name string) ([]byte, error) {
46-
paths, err := TemplatesPaths()
46+
paths, err := templatesPaths()
4747
if err != nil {
4848
return nil, err
4949
}
@@ -68,7 +68,7 @@ func Read(name string) ([]byte, error) {
6868
const Default = "default"
6969

7070
func Templates() ([]Template, error) {
71-
paths, err := TemplatesPaths()
71+
paths, err := templatesPaths()
7272
if err != nil {
7373
return nil, err
7474
}

0 commit comments

Comments
 (0)