1
Fork 0

Move configuration to Goldsmith structure

This commit is contained in:
Alex Yatskov 2024-04-06 22:30:25 -07:00
parent f5cee22324
commit 90326ba081
3 changed files with 11 additions and 16 deletions

View File

@ -10,7 +10,6 @@ type chainState struct {
cache *cache
filters filterStack
clean bool
index int
errors []error

View File

@ -3,28 +3,23 @@ package goldsmith
// Goldsmith chainable context.
type Goldsmith struct {
CacheDir string
Clean bool
chain *chainState
}
// Begin starts a chain, reading the files located in the source directory as input.
func (self *Goldsmith) Begin(sourceDir string) *Goldsmith {
self.chain = &chainState{}
if len(self.CacheDir) > 0 {
self.chain.cache = &cache{self.CacheDir}
}
self.Chain(&fileImporter{sourceDir: sourceDir})
return self
}
// Cache enables caching in cacheDir for the remainder of the chain.
func (self *Goldsmith) Cache(cacheDir string) *Goldsmith {
self.chain.cache = &cache{cacheDir}
return self
}
// Clean enables or disables removal of leftover files in the target directory.
func (self *Goldsmith) Clean(clean bool) *Goldsmith {
self.chain.clean = clean
return self
}
// Chain links a plugin instance into the chain.
func (self *Goldsmith) Chain(plugin Plugin) *Goldsmith {
context := &Context{
@ -61,7 +56,8 @@ func (self *Goldsmith) FilterPop() *Goldsmith {
// End stops a chain, writing all recieved files to targetDir as output.
func (self *Goldsmith) End(targetDir string) []error {
self.Chain(&fileExporter{targetDir: targetDir, clean: self.chain.clean})
self.Chain(&fileExporter{targetDir: targetDir, clean: self.Clean})
for _, context := range self.chain.contexts {
go context.step()
}

View File

@ -68,8 +68,8 @@ func validate(sourceDir, targetDir, cacheDir, referenceDir string, stager Stagin
}
func execute(sourceDir, targetDir, cacheDir string, stager StagingCallback) []error {
var gs goldsmith.Goldsmith
gs.Begin(sourceDir).Cache(cacheDir).Clean(true)
gs := goldsmith.Goldsmith{CacheDir: cacheDir, Clean: true}
gs.Begin(sourceDir)
stager(&gs)
return gs.End(targetDir)
}