You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: main.go
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,8 @@ var opts struct {
39
39
ModulePathstring`short:"p" long:"module_path" default:"./vendor/modules" description:"File path to install generated terraform modules, if not overridden by 'destinations:' field"`
40
40
41
41
TerrafilePathstring`short:"f" long:"terrafile_file" default:"./Terrafile" description:"File path to the Terrafile file"`
42
+
43
+
Cleanbool`short:"c" long:"clean" description:"Remove everything from destinations and module path upon fetching module(s)\n !!! WARNING !!! Removes all files and folders in the destinations including non-modules."`
42
44
}
43
45
44
46
// To be set by goreleaser on build
@@ -93,6 +95,10 @@ func main() {
93
95
log.Fatalf("failed to parse yaml file due to error: %s", err)
94
96
}
95
97
98
+
ifopts.Clean {
99
+
cleanDestinations(config)
100
+
}
101
+
96
102
// Clone modules
97
103
varwg sync.WaitGroup
98
104
_=os.RemoveAll(opts.ModulePath)
@@ -157,3 +163,32 @@ func main() {
157
163
158
164
wg.Wait()
159
165
}
166
+
167
+
funccleanDestinations(configmap[string]module) {
168
+
169
+
// Map filters duplicate destinations with key being each destination's file path
170
+
uniqueDestinations:=make(map[string]bool)
171
+
172
+
// Range over config and gather all unique destinations
173
+
for_, m:=rangeconfig {
174
+
iflen(m.Destinations) ==0 {
175
+
uniqueDestinations[opts.ModulePath] =true
176
+
continue
177
+
}
178
+
179
+
// range over Destinations and put them into map
180
+
for_, dst:=rangem.Destinations {
181
+
// Destination supposed to be conjunction of destination defined in file with module path
182
+
d:=filepath.Join(dst, opts.ModulePath)
183
+
uniqueDestinations[d] =true
184
+
}
185
+
}
186
+
187
+
fordst:=rangeuniqueDestinations {
188
+
189
+
log.Infof("[*] Removing artifacts from %s", dst)
190
+
iferr:=os.RemoveAll(dst); err!=nil {
191
+
log.Errorf("Failed to remove artifacts from %s due to error: %s", dst, err)
0 commit comments