make cleaning of target directory optional

This commit is contained in:
Alex Yatskov 2019-04-07 13:46:08 -07:00
parent 3fccb1366a
commit 5fb684701f

View File

@ -21,11 +21,13 @@ type Goldsmith struct {
fileFilters []Filter
fileCache *cache
clean bool
errors []error
mutex sync.Mutex
}
// Begin starts a chain, reading the files located in sourceDir as input.
// Begin starts a chain, reading the files located in the source directory as input.
func Begin(sourceDir string) *Goldsmith {
goldsmith := &Goldsmith{
sourceDir: sourceDir,
@ -43,6 +45,12 @@ func (goldsmith *Goldsmith) Cache(cacheDir string) *Goldsmith {
return goldsmith
}
// Clean enables or disables removal of leftover files in the target directory.
func (goldsmith *Goldsmith) Clean(clean bool) *Goldsmith {
goldsmith.clean = clean
return goldsmith
}
// Chain links a plugin instance into the chain.
func (goldsmith *Goldsmith) Chain(plugin Plugin) *Goldsmith {
goldsmith.contextHasher.Write([]byte(plugin.Name()))
@ -107,7 +115,10 @@ export:
goldsmith.exportFile(file)
}
if goldsmith.clean {
goldsmith.removeUnreferencedFiles()
}
return goldsmith.errors
}