diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-12-02 13:23:25 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-12-03 13:12:58 +0100 |
commit | d90e37e0c6e812f9913bf256c9c81aa05b7a08aa (patch) | |
tree | 7b1b14464eefec1188ca2eed53c64e4823453cc9 /commands | |
parent | 32471b57bde51c55a15dbf1db75d6e5f7232c347 (diff) |
all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
Diffstat (limited to 'commands')
-rw-r--r-- | commands/check.go | 9 | ||||
-rw-r--r-- | commands/check_darwin.go | 9 | ||||
-rw-r--r-- | commands/commandeer.go | 22 | ||||
-rw-r--r-- | commands/commands.go | 2 | ||||
-rw-r--r-- | commands/commands_test.go | 15 | ||||
-rw-r--r-- | commands/convert.go | 7 | ||||
-rw-r--r-- | commands/env.go | 25 | ||||
-rw-r--r-- | commands/genautocomplete.go | 1 | ||||
-rw-r--r-- | commands/genchromastyles.go | 4 | ||||
-rw-r--r-- | commands/gendocshelper.go | 5 | ||||
-rw-r--r-- | commands/hugo.go | 37 | ||||
-rw-r--r-- | commands/hugo_test.go | 1 | ||||
-rw-r--r-- | commands/import_jekyll.go | 12 | ||||
-rw-r--r-- | commands/import_jekyll_test.go | 116 | ||||
-rw-r--r-- | commands/list.go | 5 | ||||
-rw-r--r-- | commands/mod.go | 2 | ||||
-rw-r--r-- | commands/mod_npm.go | 2 | ||||
-rw-r--r-- | commands/new.go | 1 | ||||
-rw-r--r-- | commands/new_site.go | 1 | ||||
-rw-r--r-- | commands/new_theme.go | 2 | ||||
-rw-r--r-- | commands/nodeploy.go | 1 | ||||
-rw-r--r-- | commands/release.go | 1 | ||||
-rw-r--r-- | commands/server.go | 10 | ||||
-rw-r--r-- | commands/server_test.go | 2 | ||||
-rw-r--r-- | commands/static_syncer.go | 1 |
25 files changed, 134 insertions, 159 deletions
diff --git a/commands/check.go b/commands/check.go index f36f23969..f9be84852 100644 --- a/commands/check.go +++ b/commands/check.go @@ -26,9 +26,10 @@ type checkCmd struct { } func newCheckCmd() *checkCmd { - return &checkCmd{baseCmd: &baseCmd{cmd: &cobra.Command{ - Use: "check", - Short: "Contains some verification checks", - }, + return &checkCmd{baseCmd: &baseCmd{ + cmd: &cobra.Command{ + Use: "check", + Short: "Contains some verification checks", + }, }} } diff --git a/commands/check_darwin.go b/commands/check_darwin.go index 9291be84c..ac542916d 100644 --- a/commands/check_darwin.go +++ b/commands/check_darwin.go @@ -24,10 +24,11 @@ type checkCmd struct { } func newCheckCmd() *checkCmd { - cc := &checkCmd{baseCmd: &baseCmd{cmd: &cobra.Command{ - Use: "check", - Short: "Contains some verification checks", - }, + cc := &checkCmd{baseCmd: &baseCmd{ + cmd: &cobra.Command{ + Use: "check", + Short: "Contains some verification checks", + }, }} cc.cmd.AddCommand(newLimitCmd().getCommand()) diff --git a/commands/commandeer.go b/commands/commandeer.go index e0eae4a66..024651aad 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -16,24 +16,22 @@ package commands import ( "bytes" "errors" + "io/ioutil" + "os" + "path/filepath" + "regexp" "sync" + "time" hconfig "github.com/gohugoio/hugo/config" "golang.org/x/sync/semaphore" - "io/ioutil" - "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/hugo" jww "github.com/spf13/jwalterweatherman" - "os" - "path/filepath" - "regexp" - "time" - "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/config" @@ -156,7 +154,6 @@ func (c *commandeer) initFs(fs *hugofs.Fs) error { } func newCommandeer(mustHaveConfigFile, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) { - var rebuildDebouncer func(f func()) if running { // The time value used is tested with mass content replacements in a fairly big Hugo site. @@ -248,7 +245,6 @@ func (f *fileChangeDetector) PrepareNew() { } func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { - if c.DepsCfg == nil { c.DepsCfg = &deps.DepsCfg{} } @@ -277,7 +273,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { environment := c.h.getEnvironment(running) doWithConfig := func(cfg config.Provider) error { - if c.ftch != nil { c.ftch.flagsToConfig(cfg) } @@ -309,7 +304,8 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { Filename: c.h.cfgFile, AbsConfigDir: c.h.getConfigDir(dir), Environ: os.Environ(), - Environment: environment}, + Environment: environment, + }, cfgSetAndInit, doWithConfig) @@ -389,7 +385,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { } // To debug hard-to-find path issues. - //fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`) + // fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`) err = c.initFs(fs) if err != nil { @@ -402,7 +398,6 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { h, err = hugolib.NewHugoSites(*c.DepsCfg) c.hugoSites = h close(c.created) - }) if err != nil { @@ -418,5 +413,4 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { cfg.Logger.Infoln("Using config file:", config.ConfigFileUsed()) return nil - } diff --git a/commands/commands.go b/commands/commands.go index ce5f0ff7d..1135dc01a 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -88,6 +88,7 @@ var _ commandsBuilderGetter = (*baseBuilderCmd)(nil) type commandsBuilderGetter interface { getCommandsBuilder() *commandsBuilder } + type baseBuilderCmd struct { *baseCmd *commandsBuilder @@ -138,7 +139,6 @@ func (c *nilCommand) getCommand() *cobra.Command { } func (c *nilCommand) flagsToConfig(cfg config.Provider) { - } func (b *commandsBuilder) newHugoCmd() *hugoCmd { diff --git a/commands/commands_test.go b/commands/commands_test.go index 22e996853..0b1543169 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -35,7 +35,6 @@ import ( ) func TestExecute(t *testing.T) { - c := qt.New(t) createSite := func(c *qt.C) (string, func()) { @@ -124,7 +123,6 @@ func TestExecute(t *testing.T) { c.Assert(config, qt.Contains, "baseURL = \"http://example.org/\"") checkNewSiteInited(c, siteDir) }) - } func checkNewSiteInited(c *qt.C, basepath string) { @@ -185,7 +183,8 @@ func TestFlags(t *testing.T) { }, { name: "Persistent flags", - args: []string{"server", + args: []string{ + "server", "--config=myconfig.toml", "--configDir=myconfigdir", "--contentDir=mycontent", @@ -235,12 +234,12 @@ func TestFlags(t *testing.T) { // The flag is named i18n-warnings c.Assert(cfg.GetBool("logI18nWarnings"), qt.Equals, true) - - }}} + }, + }, + } for _, test := range tests { c.Run(test.name, func(c *qt.C) { - b := newCommandsBuilder() root := b.addAll().build() @@ -257,11 +256,9 @@ func TestFlags(t *testing.T) { test.check(c, b.commands[0].(*serverCmd)) }) } - } func TestCommandsExecute(t *testing.T) { - c := qt.New(t) dir, clean, err := createSimpleTestSite(t, testSiteConfig{}) @@ -330,7 +327,6 @@ func TestCommandsExecute(t *testing.T) { } } - } type testSiteConfig struct { @@ -399,7 +395,6 @@ Environment: {{ hugo.Environment }} `) return d, clean, nil - } func writeFile(t *testing.T, filename, content string) { diff --git a/commands/convert.go b/commands/convert.go index d8976f7ea..3047add0b 100644 --- a/commands/convert.go +++ b/commands/convert.go @@ -16,6 +16,7 @@ package commands import ( "bytes" "fmt" + "path/filepath" "strings" "time" @@ -34,14 +35,10 @@ import ( "github.com/gohugoio/hugo/hugolib" - "path/filepath" - "github.com/spf13/cobra" ) -var ( - _ cmder = (*convertCmd)(nil) -) +var _ cmder = (*convertCmd)(nil) type convertCmd struct { outputDir string diff --git a/commands/env.go b/commands/env.go index 76c16b93b..975c3bd0a 100644 --- a/commands/env.go +++ b/commands/env.go @@ -27,18 +27,19 @@ type envCmd struct { } func newEnvCmd() *envCmd { - return &envCmd{baseCmd: newBaseCmd(&cobra.Command{ - Use: "env", - Short: "Print Hugo version and environment info", - Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`, - RunE: func(cmd *cobra.Command, args []string) error { - printHugoVersion() - jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS) - jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH) - jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version()) + return &envCmd{ + baseCmd: newBaseCmd(&cobra.Command{ + Use: "env", + Short: "Print Hugo version and environment info", + Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.`, + RunE: func(cmd *cobra.Command, args []string) error { + printHugoVersion() + jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS) + jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH) + jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version()) - return nil - }, - }), + return nil + }, + }), } } diff --git a/commands/genautocomplete.go b/commands/genautocomplete.go index b0b98abb4..e8d9890cf 100644 --- a/commands/genautocomplete.go +++ b/commands/genautocomplete.go @@ -59,7 +59,6 @@ or just source them in directly: } err := cmd.Root().GenBashCompletionFile(cc.autocompleteTarget) - if err != nil { return err } diff --git a/commands/genchromastyles.go b/commands/genchromastyles.go index 6d54b6ab4..53fb2be6a 100644 --- a/commands/genchromastyles.go +++ b/commands/genchromastyles.go @@ -22,9 +22,7 @@ import ( "github.com/spf13/cobra" ) -var ( - _ cmder = (*genChromaStyles)(nil) -) +var _ cmder = (*genChromaStyles)(nil) type genChromaStyles struct { style string diff --git a/commands/gendocshelper.go b/commands/gendocshelper.go index 68ac035ee..34d45154f 100644 --- a/commands/gendocshelper.go +++ b/commands/gendocshelper.go @@ -23,9 +23,7 @@ import ( "github.com/spf13/cobra" ) -var ( - _ cmder = (*genDocsHelper)(nil) -) +var _ cmder = (*genDocsHelper)(nil) type genDocsHelper struct { target string @@ -70,5 +68,4 @@ func (g *genDocsHelper) generate() error { fmt.Println("Done!") return nil - } 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 { diff --git a/commands/hugo_test.go b/commands/hugo_test.go index 65a0416c7..4bead09f0 100644 --- a/commands/hugo_test.go +++ b/commands/hugo_test.go @@ -44,5 +44,4 @@ contentDir = "thisdoesnotexist" _, err = cmd.ExecuteC() c.Assert(err, qt.IsNil) - } diff --git a/commands/import_jekyll.go b/commands/import_jekyll.go index 2dd0fc051..b9ea56d4b 100644 --- a/commands/import_jekyll.go +++ b/commands/import_jekyll.go @@ -74,11 +74,9 @@ Import from Jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root cc.cmd.AddCommand(importJekyllCmd) return cc - } func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error { - if len(args) < 2 { return newUserError(`import from jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root_path target_path`.") } @@ -255,13 +253,11 @@ func (i *importCmd) loadJekyllConfig(fs afero.Fs, jekyllRoot string) map[string] defer f.Close() b, err := ioutil.ReadAll(f) - if err != nil { return nil } c, err := metadecoders.Default.UnmarshalToMap(b, metadecoders.YAML) - if err != nil { return nil } @@ -338,8 +334,10 @@ func (i *importCmd) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPos } } else { lowerEntryName := strings.ToLower(entry.Name()) - exceptSuffix := []string{".md", ".markdown", ".html", ".htm", - ".xml", ".textile", "rakefile", "gemfile", ".lock"} + exceptSuffix := []string{ + ".md", ".markdown", ".html", ".htm", + ".xml", ".textile", "rakefile", "gemfile", ".lock", + } isExcept := false for _, suffix := range exceptSuffix { if strings.HasSuffix(lowerEntryName, suffix) { @@ -602,8 +600,8 @@ func replaceImageTag(match string) string { } result.WriteString(">}}") return result.String() - } + func replaceOptionalPart(buffer *bytes.Buffer, partName string, part string) { if len(part) > 0 { buffer.WriteString(partName + "=\"" + part + "\" ") diff --git a/commands/import_jekyll_test.go b/commands/import_jekyll_test.go index c87c224b2..3819d03a5 100644 --- a/commands/import_jekyll_test.go +++ b/commands/import_jekyll_test.go @@ -53,25 +53,41 @@ func TestConvertJekyllMetadata(t *testing.T) { draft bool expect string }{ - {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z"}`}, - {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), true, - `{"date":"2015-10-01T00:00:00Z","draft":true}`}, - {map[interface{}]interface{}{"Permalink": "/permalink.html", "layout": "post"}, + { + map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`}, - {map[interface{}]interface{}{"permalink": "/permalink.html"}, + `{"date":"2015-10-01T00:00:00Z"}`, + }, + { + map[interface{}]interface{}{}, + "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), true, + `{"date":"2015-10-01T00:00:00Z","draft":true}`, + }, + { + map[interface{}]interface{}{"Permalink": "/permalink.html", "layout": "post"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`}, - {map[interface{}]interface{}{"category": nil, "permalink": 123}, + `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`, + }, + { + map[interface{}]interface{}{"permalink": "/permalink.html"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z"}`}, - {map[interface{}]interface{}{"Excerpt_Separator": "sep"}, + `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`, + }, + { + map[interface{}]interface{}{"category": nil, "permalink": 123}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep"}`}, - {map[interface{}]interface{}{"category": "book", "layout": "post", "Others": "Goods", "Date": "2015-10-01 12:13:11"}, + `{"date":"2015-10-01T00:00:00Z"}`, + }, + { + map[interface{}]interface{}{"Excerpt_Separator": "sep"}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, - `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z"}`}, + `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep"}`, + }, + { + map[interface{}]interface{}{"category": "book", "layout": "post", "Others": "Goods", "Date": "2015-10-01 12:13:11"}, + "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false, + `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z"}`, + }, } for _, data := range testDataList { @@ -90,44 +106,68 @@ func TestConvertJekyllContent(t *testing.T) { content string expect string }{ - {map[interface{}]interface{}{}, - "Test content\r\n<!-- more -->\npart2 content", "Test content\n<!--more-->\npart2 content"}, - {map[interface{}]interface{}{}, - "Test content\n<!-- More -->\npart2 content", "Test content\n<!--more-->\npart2 content"}, - {map[interface{}]interface{}{"excerpt_separator": "<!--sep-->"}, + { + map[interface{}]interface{}{}, + "Test content\r\n< |