summaryrefslogtreecommitdiffstats
path: root/commands/commandeer.go
diff options
context:
space:
mode:
authorsatotake <doublequotation@gmail.com>2022-04-27 02:57:04 +0900
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-08 16:56:26 +0200
commite77ca3c105bd64c5077d823d2127f6f812a4f681 (patch)
treeebbe9c310bfab1e34f9fd2e36b738fd2a37d6f11 /commands/commandeer.go
parentf2946da9e806c2bafbdd26707fe339db79bd980b (diff)
Add `clock` cli flag
Close #8787
Diffstat (limited to 'commands/commandeer.go')
-rw-r--r--commands/commandeer.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 5b192c172..20090cccd 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -15,6 +15,7 @@ package commands
import (
"errors"
+ "fmt"
"io/ioutil"
"net"
"os"
@@ -28,9 +29,11 @@ import (
"golang.org/x/sync/semaphore"
"github.com/gohugoio/hugo/common/herrors"
+ "github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/paths"
+ "github.com/spf13/cast"
jww "github.com/spf13/jwalterweatherman"
"github.com/gohugoio/hugo/common/loggers"
@@ -41,6 +44,7 @@ import (
"github.com/gohugoio/hugo/hugolib"
"github.com/spf13/afero"
+ "github.com/bep/clock"
"github.com/bep/debounce"
"github.com/bep/overlayfs"
"github.com/gohugoio/hugo/common/types"
@@ -164,6 +168,20 @@ func (c *commandeer) initFs(fs *hugofs.Fs) error {
return nil
}
+func (c *commandeer) initClock() error {
+ bt := c.Cfg.GetString("clock")
+ if bt == "" {
+ return nil
+ }
+
+ t, err := cast.StringToDateInDefaultLocation(bt, nil)
+ if err != nil {
+ return fmt.Errorf(`failed to parse "clock" flag: %s`, err)
+ }
+ htime.Clock = clock.Start(t)
+ return nil
+}
+
func newCommandeer(mustHaveConfigFile, failOnInitErr, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
var rebuildDebouncer func(f func())
if running {
@@ -341,6 +359,11 @@ func (c *commandeer) loadConfig() error {
c.configFiles = configFiles
+ err = c.initClock()
+ if err != nil {
+ return err
+ }
+
if l, ok := c.Cfg.Get("languagesSorted").(langs.Languages); ok {
c.languagesConfigured = true
c.languages = l