Debian Codegraph @

commands/release.go

raw
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 "context"
18
19 "github.com/bep/simplecobra"
20 "github.com/gohugoio/hugo/releaser"
21 "github.com/spf13/cobra"
22 )
23
24 // Note: This is a command only meant for internal use and must be run
25 // via "go run -tags release main.go release" on the actual code base that is in the release.
26 func newReleaseCommand() simplecobra.Commander {
27 var (
28 step int
29 skipPush bool
30 try bool
31 version string
32 )
33
34 return &simpleCommand{
35 name: "release",
36 short: "Release a new version of Hugo",
37 run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
38 rel, err := releaser.New(skipPush, try, step, version)
39 if err != nil {
40 return err
41 }
42
43 return rel.Run()
44 },
45 withc: func(cmd *cobra.Command, r *rootCommand) {
46 cmd.Hidden = true
47 cmd.ValidArgsFunction = cobra.NoFileCompletions
48 cmd.PersistentFlags().BoolVarP(&skipPush, "skip-push", "", false, "skip pushing to remote")
49 cmd.PersistentFlags().BoolVarP(&try, "try", "", false, "no changes")
50 cmd.PersistentFlags().IntVarP(&step, "step", "", 0, "step to run (1: set new version 2: prepare next dev version)")
51 cmd.PersistentFlags().StringVarP(&version, "version", "", "", "version to release (derived from branch name if not set)")
52 _ = cmd.RegisterFlagCompletionFunc("step", cobra.FixedCompletions([]string{"1", "2"}, cobra.ShellCompDirectiveNoFileComp))
53 },
54 }
55 }