hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

release.go (2058B)

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