deploy: Fix deploy defaults for non-zero flag values (e.g. maxDeletes, invalidateCDN)

This was broken in the config rewrite in Hugo 0.112.0.

The workaround is to be explicit about setting these flag values (even if just using the defaults), e.g.:

```
hugo deploy --invalidateCDN --maxDeletes 256
```

Fixes #11127
This commit is contained in:
Bjørn Erik Pedersen 2023-06-18 18:35:11 +02:00
parent 1b85303ac2
commit 12dc9a6e4a
3 changed files with 13 additions and 8 deletions

View file

@ -63,9 +63,9 @@ documentation.
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target") cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
cmd.Flags().Bool("dryRun", false, "dry run") cmd.Flags().Bool("dryRun", false, "dry run")
cmd.Flags().Bool("force", false, "force upload of all files") cmd.Flags().Bool("force", false, "force upload of all files")
cmd.Flags().Bool("invalidateCDN", true, "invalidate the CDN cache listed in the deployment target") cmd.Flags().Bool("invalidateCDN", deploy.DefaultConfig.InvalidateCDN, "invalidate the CDN cache listed in the deployment target")
cmd.Flags().Int("maxDeletes", 256, "maximum # of files to delete, or -1 to disable") cmd.Flags().Int("maxDeletes", deploy.DefaultConfig.MaxDeletes, "maximum # of files to delete, or -1 to disable")
cmd.Flags().Int("workers", 10, "number of workers to transfer files. defaults to 10") cmd.Flags().Int("workers", deploy.DefaultConfig.Workers, "number of workers to transfer files. defaults to 10")
}, },
} }
} }

View file

@ -127,11 +127,16 @@ func (m *Matcher) Matches(path string) bool {
return m.re.MatchString(path) return m.re.MatchString(path)
} }
var DefaultConfig = DeployConfig{
Workers: 10,
InvalidateCDN: true,
MaxDeletes: 256,
}
// DecodeConfig creates a config from a given Hugo configuration. // DecodeConfig creates a config from a given Hugo configuration.
func DecodeConfig(cfg config.Provider) (DeployConfig, error) { func DecodeConfig(cfg config.Provider) (DeployConfig, error) {
var (
dcfg DeployConfig dcfg := DefaultConfig
)
if !cfg.IsSet(deploymentConfigKey) { if !cfg.IsSet(deploymentConfigKey) {
return dcfg, nil return dcfg, nil

View file

@ -3,10 +3,10 @@
hugo deploy -h hugo deploy -h
stdout 'Deploy your site to a Cloud provider\.' stdout 'Deploy your site to a Cloud provider\.'
mkdir mybucket mkdir mybucket
hugo deploy --target mydeployment hugo deploy --target mydeployment --invalidateCDN=false
grep 'hello' mybucket/index.html grep 'hello' mybucket/index.html
replace public/index.html 'hello' 'changed' replace public/index.html 'hello' 'changed'
hugo deploy --target mydeployment --invalidateCDN --dryRun hugo deploy --target mydeployment --dryRun
stdout 'Would upload: index.html' stdout 'Would upload: index.html'
stdout 'Would invalidate CloudFront CDN with ID foobar' stdout 'Would invalidate CloudFront CDN with ID foobar'
-- hugo.toml -- -- hugo.toml --