Add version command to print golangci-lint version

Fixes #675
This commit is contained in:
M. Ángel 2019-10-01 10:03:14 +02:00 committed by Trevor Pounds
parent 6d786b50ae
commit 5e54b3334e
2 changed files with 18 additions and 0 deletions

View File

@ -82,6 +82,7 @@ func NewExecutor(version, commit, date string) *Executor {
e.initLinters() e.initLinters()
e.initConfig() e.initConfig()
e.initCompletion() e.initCompletion()
e.initVersion()
// init e.cfg by values from config: flags parse will see these values // init e.cfg by values from config: flags parse will see these values
// like the default ones. It will overwrite them only if the same option // like the default ones. It will overwrite them only if the same option

17
pkg/commands/version.go Normal file
View File

@ -0,0 +1,17 @@
package commands
import (
"github.com/spf13/cobra"
)
func (e *Executor) initVersion() {
versionCmd := &cobra.Command{
Use: "version",
Short: "Version",
Run: func(cmd *cobra.Command, _ []string) {
cmd.Printf("golangci-lint has version %s built from %s on %s\n", e.version, e.commit, e.date)
},
}
e.rootCmd.AddCommand(versionCmd)
}