commands: Re-add the missing releaser command

This commit is contained in:
Bjørn Erik Pedersen 2018-04-16 08:23:32 +02:00
parent 7c597c7d75
commit f21b827f7b
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
4 changed files with 54 additions and 2 deletions

View file

@ -49,6 +49,7 @@ func (b *commandsBuilder) addAll() *commandsBuilder {
newListCmd(),
newImportCmd(),
newGenCmd(),
createReleaser(),
)
return b
@ -62,7 +63,11 @@ func (b *commandsBuilder) build() *hugoCmd {
func addCommands(root *cobra.Command, commands ...cmder) {
for _, command := range commands {
root.AddCommand(command.getCommand())
cmd := command.getCommand()
if cmd == nil {
continue
}
root.AddCommand(cmd)
}
}
@ -110,6 +115,19 @@ type hugoCmd struct {
c *commandeer
}
var _ cmder = (*nilCommand)(nil)
type nilCommand struct {
}
func (c *nilCommand) getCommand() *cobra.Command {
return nil
}
func (c *nilCommand) flagsToConfig(cfg config.Provider) {
}
func (b *commandsBuilder) newHugoCmd() *hugoCmd {
cc := &hugoCmd{}

View file

@ -118,6 +118,9 @@ func TestCommandsPersistentFlags(t *testing.T) {
root := b.addAll().build()
for _, c := range b.commands {
if c.getCommand() == nil {
continue
}
// We are only intereseted in the flag handling here.
c.getCommand().RunE = noOpRunE
}

View file

@ -18,10 +18,13 @@ package commands
import (
"errors"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/releaser"
"github.com/spf13/cobra"
)
var _ cmder = (*releaseCommandeer)(nil)
type releaseCommandeer struct {
cmd *cobra.Command
@ -31,7 +34,7 @@ type releaseCommandeer struct {
try bool
}
func createReleaser() *releaseCommandeer {
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{
@ -53,6 +56,14 @@ func createReleaser() *releaseCommandeer {
return r
}
func (c *releaseCommandeer) getCommand() *cobra.Command {
return c.cmd
}
func (c *releaseCommandeer) flagsToConfig(cfg config.Provider) {
}
func (r *releaseCommandeer) release() error {
if r.version == "" {
return errors.New("must set the --rel flag to the relevant version number")

20
commands/release_noop.go Normal file
View file

@ -0,0 +1,20 @@
// +build !release
// Copyright 2018 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.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package commands
func createReleaser() cmder {
return &nilCommand{}
}