summaryrefslogtreecommitdiffstats
path: root/commands/release.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-04 18:24:36 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-16 18:01:29 +0200
commit241b21b0fd34d91fccb2ce69874110dceae6f926 (patch)
treed4e0118eac7e9c42f065815447a70805f8d6ad3e /commands/release.go
parent6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff)
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
Diffstat (limited to 'commands/release.go')
-rw-r--r--commands/release.go79
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()
}