gitee.com/mirrors/Hugo-Go@v0.47.1/commands/release.go (about) 1 // +build release 2 3 // Copyright 2017-present The Hugo Authors. All rights reserved. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package commands 17 18 import ( 19 "errors" 20 21 "github.com/gohugoio/hugo/config" 22 "github.com/gohugoio/hugo/releaser" 23 "github.com/spf13/cobra" 24 ) 25 26 var _ cmder = (*releaseCommandeer)(nil) 27 28 type releaseCommandeer struct { 29 cmd *cobra.Command 30 31 version string 32 33 skipPublish bool 34 try bool 35 } 36 37 func createReleaser() cmder { 38 // Note: This is a command only meant for internal use and must be run 39 // via "go run -tags release main.go release" on the actual code base that is in the release. 40 r := &releaseCommandeer{ 41 cmd: &cobra.Command{ 42 Use: "release", 43 Short: "Release a new version of Hugo.", 44 Hidden: true, 45 }, 46 } 47 48 r.cmd.RunE = func(cmd *cobra.Command, args []string) error { 49 return r.release() 50 } 51 52 r.cmd.PersistentFlags().StringVarP(&r.version, "rel", "r", "", "new release version, i.e. 0.25.1") 53 r.cmd.PersistentFlags().BoolVarP(&r.skipPublish, "skip-publish", "", false, "skip all publishing pipes of the release") 54 r.cmd.PersistentFlags().BoolVarP(&r.try, "try", "", false, "simulate a release, i.e. no changes") 55 56 return r 57 } 58 59 func (c *releaseCommandeer) getCommand() *cobra.Command { 60 return c.cmd 61 } 62 63 func (c *releaseCommandeer) flagsToConfig(cfg config.Provider) { 64 65 } 66 67 func (r *releaseCommandeer) release() error { 68 if r.version == "" { 69 return errors.New("must set the --rel flag to the relevant version number") 70 } 71 return releaser.New(r.version, r.skipPublish, r.try).Run() 72 }