Skip to content

Commit 1e4326c

Browse files
committed
Mark dotfiles which have expanded envs
1 parent 4a04639 commit 1e4326c

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ type SourceConfig struct {
6868
// environment variables. These generally look like: ${HOME}. This
6969
// configuration is useful for config files that do not support environment
7070
// variable expansion.
71-
//
72-
// TODO: Decide if this is actually something we want to implement. It
73-
// makes diffing a bit harder since we can't straight compare the
74-
// file size for single files anymore.
7571
ExpandEnvironment []string `yaml:"expand_environment"`
7672
}
7773

resolver/resolver.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Dotfile struct {
2424
Path string
2525
Removed bool
2626
Added bool
27+
ExpandEnv bool
2728
Sources []*SourceFile
2829
InstallFiles []string
2930
}
@@ -185,7 +186,7 @@ func resolveOverrides(dotfiles dotfileMap, overrideSuffix string) {
185186
}
186187

187188
// resolveInstalls looks for dotfiles ending in the installSuffix and will map
188-
// them to the dorfile theyare named after, or any dotfile's that exist within
189+
// them to the dorfile they are named after, or any dotfile's that exist within
189190
// the directory they are named after.
190191
func resolveInstalls(dotfiles dotfileMap, installSuffix string) {
191192
for path, dotfile := range dotfiles {
@@ -233,6 +234,16 @@ func resolveRemoved(dotfiles dotfileMap, oldDotfiles []string) {
233234
}
234235
}
235236

237+
func resolveExpandEnv(dotfiles dotfileMap, expandPaths []string) {
238+
for _, expandTarget := range expandPaths {
239+
for path, dotfile := range dotfiles {
240+
if expandTarget == path {
241+
dotfile.ExpandEnv = true
242+
}
243+
}
244+
}
245+
}
246+
236247
// sourceLoader provides a list of files given a source path.
237248
var sourceLoader = func(sourcePath string) []string {
238249
sources := []string{}
@@ -271,5 +282,8 @@ func ResolveDotfiles(conf config.SourceConfig, lockfile config.SourceLockfile) D
271282
resolveInstalls(dotfiles, "."+conf.InstallSuffix)
272283
resolveRemoved(dotfiles, lockfile.InstalledFiles)
273284

285+
// Mark dotfiles which will have environment expansion
286+
resolveExpandEnv(dotfiles, conf.ExpandEnvironment)
287+
274288
return dotfiles.asList()
275289
}

resolver/resolver_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func TestResolveDotfiles(t *testing.T) {
1515
SourceFiles []string
1616
ExistingFiles []string
1717
Groups []string
18+
ExpandEnv []string
1819
OverrideSuffix string
1920
InstallSuffix string
2021
Expected Dotfiles
@@ -54,6 +55,7 @@ func TestResolveDotfiles(t *testing.T) {
5455
},
5556
ExistingFiles: []string{"bash/conf", "environment"},
5657
Groups: []string{"base", "machines/desktop", "machines/server"},
58+
ExpandEnv: []string{"generic-config"},
5759
OverrideSuffix: "ovrd",
5860
InstallSuffix: "inst",
5961
Expected: Dotfiles{
@@ -105,8 +107,9 @@ func TestResolveDotfiles(t *testing.T) {
105107
},
106108
},
107109
{
108-
Path: "generic-config",
109-
Added: true,
110+
Path: "generic-config",
111+
ExpandEnv: true,
112+
Added: true,
110113
Sources: []*SourceFile{
111114
{
112115
Group: "base",
@@ -260,8 +263,8 @@ func TestResolveDotfiles(t *testing.T) {
260263
},
261264
}
262265

263-
ogSourceLoader := sourceLoader
264-
defer func() { sourceLoader = ogSourceLoader }()
266+
origSourceLoader := sourceLoader
267+
defer func() { sourceLoader = origSourceLoader }()
265268

266269
for _, test := range tests {
267270
if test.OverrideSuffix == "" {
@@ -273,9 +276,10 @@ func TestResolveDotfiles(t *testing.T) {
273276
}
274277

275278
conf := config.SourceConfig{
276-
BaseGroups: []string{},
277-
OverrideSuffix: test.OverrideSuffix,
278-
InstallSuffix: test.InstallSuffix,
279+
BaseGroups: []string{},
280+
OverrideSuffix: test.OverrideSuffix,
281+
InstallSuffix: test.InstallSuffix,
282+
ExpandEnvironment: test.ExpandEnv,
279283
}
280284

281285
lockfile := config.SourceLockfile{

0 commit comments

Comments
 (0)