From 5e54b3334ee9beeb6fd6d4dfe7bd57343d5f2af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20=C3=81ngel?= Date: Tue, 1 Oct 2019 10:03:14 +0200 Subject: [PATCH] Add version command to print golangci-lint version Fixes #675 --- pkg/commands/executor.go | 1 + pkg/commands/version.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 pkg/commands/version.go diff --git a/pkg/commands/executor.go b/pkg/commands/executor.go index 42b179db..62429e72 100644 --- a/pkg/commands/executor.go +++ b/pkg/commands/executor.go @@ -82,6 +82,7 @@ func NewExecutor(version, commit, date string) *Executor { e.initLinters() e.initConfig() e.initCompletion() + e.initVersion() // 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 diff --git a/pkg/commands/version.go b/pkg/commands/version.go new file mode 100644 index 00000000..fdb5aa88 --- /dev/null +++ b/pkg/commands/version.go @@ -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) +}