diff options
Diffstat (limited to 'commands/release.go')
-rw-r--r-- | commands/release.go | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/commands/release.go b/commands/release.go index 2072f3eb2..fe3c5efb6 100644 --- a/commands/release.go +++ b/commands/release.go @@ -1,7 +1,4 @@ -//go:build release -// +build release - -// Copyright 2017-present The Hugo Authors. All rights reserved. +// Copyright 2023 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,55 +14,39 @@ package commands import ( - "github.com/gohugoio/hugo/config" + "context" + + "github.com/bep/simplecobra" "github.com/gohugoio/hugo/releaser" "github.com/spf13/cobra" ) -var _ cmder = (*releaseCommandeer)(nil) - -type releaseCommandeer struct { - cmd *cobra.Command - - step int - skipPush bool - try bool -} - -func createReleaser() cmder { - // Note: This is a command only meant for internal use and must be run - // via "go run -tags release main.go release" on the actual code base that is in the release. - r := &releaseCommandeer{ - cmd: &cobra.Command{ - Use: "release", - Short: "Release a new version of Hugo.", - Hidden: true, +// Note: This is a command only meant for internal use and must be run +// via "go run -tags release main.go release" on the actual code base that is in the release. +func newReleaseCommand() simplecobra.Commander { + + var ( + step int + skipPush bool + try bool + ) + + return &simpleCommand{ + name: "release", + short: "Release a new version of Hugo.", + run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error { + rel, err := releaser.New(skipPush, try, step) + if err != nil { + return err + } + + return rel.Run() + }, + withc: func(cmd *cobra.Command) { + cmd.Hidden = true + cmd.PersistentFlags().BoolVarP(&skipPush, "skip-push", "", false, "skip pushing to remote") + cmd.PersistentFlags().BoolVarP(&try, "try", "", false, "no changes") + cmd.PersistentFlags().IntVarP(&step, "step", "", 0, "step to run (1: set new version 2: prepare next dev version)") }, } - - r.cmd.RunE = func(cmd *cobra.Command, args []string) error { - return r.release() - } - - r.cmd.PersistentFlags().BoolVarP(&r.skipPush, "skip-push", "", false, "skip pushing to remote") - r.cmd.PersistentFlags().BoolVarP(&r.try, "try", "", false, "no changes") - r.cmd.PersistentFlags().IntVarP(&r.step, "step", "", 0, "step to run (1: set new version 2: prepare next dev version)") - - return r -} - -func (c *releaseCommandeer) getCommand() *cobra.Command { - return c.cmd -} - -func (c *releaseCommandeer) flagsToConfig(cfg config.Provider) { -} - -func (r *releaseCommandeer) release() error { - rel, err := releaser.New(r.skipPush, r.try, r.step) - if err != nil { - return err - } - - return rel.Run() } |