Skip to content

Commit 2b0b3b8

Browse files
committed
commands: Print the "deploy not available" error message even if flags provided
Fixes #13012
1 parent 801035b commit 2b0b3b8

File tree

5 files changed

+67
-12
lines changed

5 files changed

+67
-12
lines changed

commands/deploy.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121

2222
"github.com/gohugoio/hugo/deploy"
23-
"github.com/gohugoio/hugo/deploy/deployconfig"
2423

2524
"github.com/bep/simplecobra"
2625
"github.com/spf13/cobra"
@@ -47,17 +46,7 @@ documentation.
4746
return deployer.Deploy(ctx)
4847
},
4948
withc: func(cmd *cobra.Command, r *rootCommand) {
50-
cmd.ValidArgsFunction = cobra.NoFileCompletions
51-
cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one")
52-
_ = cmd.RegisterFlagCompletionFunc("target", cobra.NoFileCompletions)
53-
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
54-
cmd.Flags().Bool("dryRun", false, "dry run")
55-
cmd.Flags().Bool("force", false, "force upload of all files")
56-
cmd.Flags().Bool("invalidateCDN", deployconfig.DefaultConfig.InvalidateCDN, "invalidate the CDN cache listed in the deployment target")
57-
cmd.Flags().Int("maxDeletes", deployconfig.DefaultConfig.MaxDeletes, "maximum # of files to delete, or -1 to disable")
58-
_ = cmd.RegisterFlagCompletionFunc("maxDeletes", cobra.NoFileCompletions)
59-
cmd.Flags().Int("workers", deployconfig.DefaultConfig.Workers, "number of workers to transfer files. defaults to 10")
60-
_ = cmd.RegisterFlagCompletionFunc("workers", cobra.NoFileCompletions)
49+
applyDeployFlags(cmd, r)
6150
},
6251
}
6352
}

commands/deploy_flags.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package commands
15+
16+
import (
17+
"github.com/gohugoio/hugo/deploy/deployconfig"
18+
"github.com/spf13/cobra"
19+
)
20+
21+
func applyDeployFlags(cmd *cobra.Command, r *rootCommand) {
22+
cmd.ValidArgsFunction = cobra.NoFileCompletions
23+
cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one")
24+
_ = cmd.RegisterFlagCompletionFunc("target", cobra.NoFileCompletions)
25+
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
26+
cmd.Flags().Bool("dryRun", false, "dry run")
27+
cmd.Flags().Bool("force", false, "force upload of all files")
28+
cmd.Flags().Bool("invalidateCDN", deployconfig.DefaultConfig.InvalidateCDN, "invalidate the CDN cache listed in the deployment target")
29+
cmd.Flags().Int("maxDeletes", deployconfig.DefaultConfig.MaxDeletes, "maximum # of files to delete, or -1 to disable")
30+
_ = cmd.RegisterFlagCompletionFunc("maxDeletes", cobra.NoFileCompletions)
31+
cmd.Flags().Int("workers", deployconfig.DefaultConfig.Workers, "number of workers to transfer files. defaults to 10")
32+
_ = cmd.RegisterFlagCompletionFunc("workers", cobra.NoFileCompletions)
33+
}

commands/deploy_off.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func newDeployCommand() simplecobra.Commander {
4444
return errors.New("deploy not supported in this version of Hugo; install a release with 'withdeploy' in the archive filename or build yourself with the 'withdeploy' build tag. Also see https://github.com/gohugoio/hugo/pull/12995")
4545
},
4646
withc: func(cmd *cobra.Command, r *rootCommand) {
47+
applyDeployFlags(cmd, r)
4748
cmd.Hidden = true
4849
},
4950
}

main_withdeploy_off_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2024 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
//go:build !withdeploy
15+
// +build !withdeploy
16+
17+
package main
18+
19+
import (
20+
"testing"
21+
22+
"github.com/rogpeppe/go-internal/testscript"
23+
)
24+
25+
func TestWithdeploy(t *testing.T) {
26+
p := commonTestScriptsParam
27+
p.Dir = "testscripts/withdeploy-off"
28+
testscript.Run(t, p)
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
! hugo deploy --force
2+
# Issue 13012
3+
stderr 'deploy not supported in this version of Hugo'

0 commit comments

Comments
 (0)