Skip to content

Commit

Permalink
Merge pull request #696 from hairyhenderson/use-cobra-version
Browse files Browse the repository at this point in the history
Use cobra's built-in --version flag instead of implementing separately
  • Loading branch information
hairyhenderson authored Mar 6, 2020
2 parents 1d15b4c + 6740473 commit 307e0fa
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
14 changes: 1 addition & 13 deletions cmd/gomplate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"os/signal"
Expand All @@ -21,7 +20,6 @@ import (
)

var (
printVer bool
verbose bool
execPipe bool
opts gomplate.Config
Expand All @@ -30,10 +28,6 @@ var (
postRunInput *bytes.Buffer
)

func printVersion(name string) {
fmt.Printf("%s version %s\n", name, version.Version)
}

// postRunExec - if templating succeeds, the command following a '--' will be executed
func postRunExec(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
Expand Down Expand Up @@ -101,12 +95,8 @@ func newGomplateCmd() *cobra.Command {
Use: "gomplate",
Short: "Process text files with Go templates",
PreRunE: validateOpts,
Version: version.Version,
RunE: func(cmd *cobra.Command, args []string) error {
if printVer {
printVersion(cmd.Name())
return nil
}

if v, _ := cmd.Flags().GetBool("verbose"); v {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
Expand Down Expand Up @@ -169,8 +159,6 @@ func initFlags(command *cobra.Command) {
command.Flags().StringVar(&opts.RDelim, "right-delim", rdDefault, "override the default right-`delimiter` [$GOMPLATE_RIGHT_DELIM]")

command.Flags().BoolVarP(&verbose, "verbose", "V", false, "output extra information about what gomplate is doing")

command.Flags().BoolVarP(&printVer, "version", "v", false, "print the version")
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/sergi/go-diff v1.1.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v0.0.6
github.com/spf13/cobra v0.0.7-0.20200228181340-95f2f73ed97e
github.com/stretchr/testify v1.5.1
github.com/ugorji/go/codec v1.1.7
github.com/zealic/xignore v0.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs=
github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v0.0.7-0.20200228181340-95f2f73ed97e h1:hPJtePycGk1fr1xu9P0tZH7ovSWENwxYTs05S+YCWoM=
github.com/spf13/cobra v0.0.7-0.20200228181340-95f2f73ed97e/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down

0 comments on commit 307e0fa

Please sign in to comment.