summaryrefslogtreecommitdiffstats
path: root/commands/hugo.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/hugo.go')
-rw-r--r--commands/hugo.go37
1 files changed, 7 insertions, 30 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index 58f33b775..b850f7e65 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -19,10 +19,16 @@ import (
"context"
"fmt"
"io/ioutil"
+ "os"
"os/signal"
+ "path/filepath"
+ "runtime"
"runtime/pprof"
"runtime/trace"
+ "strings"
"sync/atomic"
+ "syscall"
+ "time"
"github.com/gohugoio/hugo/hugofs"
@@ -34,18 +40,10 @@ import (
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/terminal"
- "syscall"
-
"github.com/gohugoio/hugo/hugolib/filesystems"
"golang.org/x/sync/errgroup"
- "os"
- "path/filepath"
- "runtime"
- "strings"
- "time"
-
"github.com/gohugoio/hugo/config"
flag "github.com/spf13/pflag"
@@ -82,7 +80,6 @@ func (r Response) IsUserError() bool {
// Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
// The args are usually filled with os.Args[1:].
func Execute(args []string) Response {
-
hugoCmd := newCommandsBuilder().addAll().build()
cmd := hugoCmd.getCommand()
cmd.SetArgs(args)
@@ -120,14 +117,12 @@ func initializeConfig(mustHaveConfigFile, running bool,
h *hugoBuilderCommon,
f flagsToConfigHandler,
cfgInit func(c *commandeer) error) (*commandeer, error) {
-
c, err := newCommandeer(mustHaveConfigFile, running, h, f, cfgInit)
if err != nil {
return nil, err
}
return c, nil
-
}
func (c *commandeer) createLogger(cfg config.Provider, running bool) (loggers.Logger, error) {
@@ -246,7 +241,6 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
setValueFromFlag(cmd.Flags(), "destination", cfg, "publishDir", false)
setValueFromFlag(cmd.Flags(), "i18n-warnings", cfg, "logI18nWarnings", false)
setValueFromFlag(cmd.Flags(), "path-warnings", cfg, "logPathWarnings", false)
-
}
func setValueFromFlag(flags *flag.FlagSet, key string, cfg config.Provider, targetKey string, force bool) {
@@ -282,7 +276,6 @@ func isTerminal() bool {
}
func (c *commandeer) fullBuild() error {
-
var (
g errgroup.Group
langCount map[string]uint64
@@ -298,7 +291,6 @@ func (c *commandeer) fullBuild() error {
}
copyStaticFunc := func() error {
-
cnt, err := c.copyStatic()
if err != nil {
return errors.Wrap(err, "Error copying static files")
@@ -346,7 +338,6 @@ func (c *commandeer) fullBuild() error {
}
return nil
-
}
func (c *commandeer) initCPUProfile() (func(), error) {
@@ -419,7 +410,6 @@ func (c *commandeer) initMutexProfile() (func(), error) {
pprof.Lookup("mutex").WriteTo(f, 0)
f.Close()
}, nil
-
}
func (c *commandeer) initMemTicker() func() {
@@ -429,7 +419,6 @@ func (c *commandeer) initMemTicker() func() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("\n\nAlloc = %v\nTotalAlloc = %v\nSys = %v\nNumGC = %v\n\n", formatByteCount(m.Alloc), formatByteCount(m.TotalAlloc), formatByteCount(m.Sys), m.NumGC)
-
}
go func() {
@@ -442,7 +431,6 @@ func (c *commandeer) initMemTicker() func() {
printMem()
return
}
-
}
}()
@@ -452,7 +440,6 @@ func (c *commandeer) initMemTicker() func() {
}
func (c *commandeer) initProfiling() (func(), error) {
-
stopCPUProf, err := c.initCPUProfile()
if err != nil {
return nil, err
@@ -538,7 +525,7 @@ func (c *commandeer) build() error {
checkErr(c.Logger, err)
defer watcher.Close()
- var sigs = make(chan os.Signal, 1)
+ sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
@@ -584,7 +571,6 @@ func (c *commandeer) copyStatic() (map[string]uint64, error) {
}
func (c *commandeer) doWithPublishDirs(f func(sourceFs *filesystems.SourceFilesystem) (uint64, error)) (map[string]uint64, error) {
-
langCount := make(map[string]uint64)
staticFilesystems := c.hugo().BaseFs.SourceFilesystems.Static
@@ -712,7 +698,6 @@ func (c *commandeer) getDirList() ([]string, error) {
}
return nil
-
}
watchFiles := c.hugo().PathSpec.BaseFs.WatchDirs()
@@ -753,7 +738,6 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
c.buildErr = nil
visited := c.visitedURLs.PeekAllSet()
if c.fastRenderMode {
-
// Make sure we always render the home pages
for _, l := range c.languages {
langPath := c.hugo().PathSpec.GetLangSubDir(l.Lang)
@@ -763,7 +747,6 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
home := c.hugo().PathSpec.PrependBasePath("/"+langPath, false)
visited[home] = true
}
-
}
return c.hugo().Build(hugolib.BuildCfg{RecentlyVisited: visited, ErrRecovery: c.wasError}, events...)
}
@@ -793,13 +776,11 @@ func (c *commandeer) fullRebuild(changeType string) {
c.fullRebuildSem.Acquire(context.Background(), 1)
go func() {
-
defer c.fullRebuildSem.Release(1)
c.printChangeDetected(changeType)
defer func() {
-
// Allow any file system events to arrive back.
// This will block any rebuild on config changes for the
// duration of the sleep.
@@ -848,7 +829,6 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
}
watcher, err := watcher.New(1 * time.Second)
-
if err != nil {
return nil, err
}
@@ -909,7 +889,6 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
staticSyncer *staticSyncer,
evs []fsnotify.Event,
configSet map[string]bool) {
-
defer func() {
c.wasError = false
}()
@@ -950,7 +929,6 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
time.Sleep(100 * time.Millisecond)
}
}
-
}
// Config file(s) changed. Need full rebuild.
@@ -1194,7 +1172,6 @@ func partitionDynamicEvents(sourceFs *filesystems.SourceFilesystems, events []fs
}
}
return
-
}
func pickOneWriteOrCreatePath(events []fsnotify.Event) string {