diff --git a/goldsmith.go b/goldsmith.go index 252b1aa..394c272 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -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) } - goldsmith.removeUnreferencedFiles() + if goldsmith.clean { + goldsmith.removeUnreferencedFiles() + } + return goldsmith.errors }