diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-05 10:13:41 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-05 10:23:29 +0200 |
commit | e31b1d194655ac3a38fe903ff3995806b129b88a (patch) | |
tree | 8ffac9e39952c9f547b7b4e92620c1c05c84bfc5 /commands | |
parent | 43a23239b2e3ad602c06d9af0b648e0304fc8744 (diff) |
commands: Make the --poll flag a duration
So you can do:
```
hugo server --poll 700ms
```
See #8720
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commands.go | 4 | ||||
-rw-r--r-- | commands/hugo.go | 19 |
2 files changed, 16 insertions, 7 deletions
diff --git a/commands/commands.go b/commands/commands.go index 6aacc8e0b..235f35917 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -204,7 +204,7 @@ type hugoBuilderCommon struct { environment string buildWatch bool - poll bool + poll string gc bool @@ -292,7 +292,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&cc.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. http://spf13.com/") cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date and author info to the pages") cmd.Flags().BoolVar(&cc.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build") - cmd.Flags().BoolVar(&cc.poll, "poll", false, "use a poll based approach to watch for file system changes") + cmd.Flags().StringVar(&cc.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes") cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions") cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics") diff --git a/commands/hugo.go b/commands/hugo.go index 7f3b41048..86aa8d573 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -30,6 +30,8 @@ import ( "syscall" "time" + "github.com/gohugoio/hugo/common/types" + "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/resources/page" @@ -820,7 +822,7 @@ func (c *commandeer) fullRebuild(changeType string) { } // newWatcher creates a new watcher to watch filesystem events. -func (c *commandeer) newWatcher(poll bool, dirList ...string) (*watcher.Batcher, error) { +func (c *commandeer) newWatcher(pollIntervalStr string, dirList ...string) (*watcher.Batcher, error) { if runtime.GOOS == "darwin" { tweakLimit() } @@ -830,10 +832,17 @@ func (c *commandeer) newWatcher(poll bool, dirList ...string) (*watcher.Batcher, return nil, err } - // The second interval is used by the poll based watcher. - // Setting a shorter interval would make it snappier, - // but it would consume more CPU. - watcher, err := watcher.New(500*time.Millisecond, 700*time.Millisecond, poll) + var pollInterval time.Duration + poll := pollIntervalStr != "" + if poll { + pollInterval, err = types.ToDurationE(pollIntervalStr) + if err != nil { + return nil, fmt.Errorf("invalid value for flag poll: %s", err) + } + c.logger.Printf("Use watcher with poll interval %v", pollInterval) + } + + watcher, err := watcher.New(500*time.Millisecond, pollInterval, poll) if err != nil { return nil, err } |