diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-11-25 20:43:56 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2020-03-05 20:36:03 -0500 |
| commit | 6740473594e3cc0323d41648b6312b5bbc13cf87 (patch) | |
| tree | a93cb4df9a747d1c5172848ad232e29e7e325916 /cmd | |
| parent | 1d15b4c5e8a866a1f8d49c4daf9a08552dfc2478 (diff) | |
Use cobra's built-in --version flag instead of implementing separately
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/gomplate/main.go | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/cmd/gomplate/main.go b/cmd/gomplate/main.go index 4fd6c402..62c85fdb 100644 --- a/cmd/gomplate/main.go +++ b/cmd/gomplate/main.go @@ -7,7 +7,6 @@ package main import ( "bytes" "context" - "fmt" "os" "os/exec" "os/signal" @@ -21,7 +20,6 @@ import ( ) var ( - printVer bool verbose bool execPipe bool opts gomplate.Config @@ -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 { @@ -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) } @@ -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() { |
