Move configuration to Goldsmith structure
This commit is contained in:
parent
f5cee22324
commit
90326ba081
@ -10,7 +10,6 @@ type chainState struct {
|
||||
|
||||
cache *cache
|
||||
filters filterStack
|
||||
clean bool
|
||||
index int
|
||||
|
||||
errors []error
|
||||
|
22
goldsmith.go
22
goldsmith.go
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user