mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-14 20:33:59 +02:00
Make sure that HugoSites is always closed when done
Including all the integration tests.
This commit is contained in:
@@ -42,6 +42,7 @@ import (
|
||||
"github.com/gohugoio/hugo/common/hugo"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/paths"
|
||||
"github.com/gohugoio/hugo/common/types"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/config/allconfig"
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
@@ -66,6 +67,12 @@ func Execute(args []string) error {
|
||||
}
|
||||
args = mapLegacyArgs(args)
|
||||
cd, err := x.Execute(context.Background(), args)
|
||||
if cd != nil {
|
||||
if closer, ok := cd.Root.Command.(types.Closer); ok {
|
||||
closer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == errHelp {
|
||||
cd.CobraCommand.Help()
|
||||
@@ -149,6 +156,18 @@ func (r *rootCommand) isVerbose() bool {
|
||||
return r.logger.Level() <= logg.LevelInfo
|
||||
}
|
||||
|
||||
func (r *rootCommand) Close() error {
|
||||
if r.hugoSites != nil {
|
||||
r.hugoSites.DeleteFunc(func(key configKey, value *hugolib.HugoSites) bool {
|
||||
if value != nil {
|
||||
value.Close()
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) {
|
||||
h, err := r.Hugo(cfg)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user