Skip to content

Commit b9a67e6

Browse files
authored
dev: display version in verbose mode (#4771)
1 parent 88f60c8 commit b9a67e6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/commands/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error
152152
return err
153153
}
154154

155+
c.log.Infof(c.buildInfo.String())
156+
155157
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
156158

157159
err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})

pkg/commands/version.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ type BuildInfo struct {
1919
Date string `json:"date"`
2020
}
2121

22+
func (b BuildInfo) String() string {
23+
return fmt.Sprintf("golangci-lint has version %s built with %s from %s on %s",
24+
b.Version, b.GoVersion, b.Commit, b.Date)
25+
}
26+
2227
type versionInfo struct {
2328
Info BuildInfo
2429
BuildInfo *debug.BuildInfo
@@ -92,7 +97,6 @@ func (c *versionCommand) execute(_ *cobra.Command, _ []string) error {
9297
}
9398

9499
func printVersion(w io.Writer, info BuildInfo) error {
95-
_, err := fmt.Fprintf(w, "golangci-lint has version %s built with %s from %s on %s\n",
96-
info.Version, info.GoVersion, info.Commit, info.Date)
100+
_, err := fmt.Fprintln(w, info.String())
97101
return err
98102
}

0 commit comments

Comments
 (0)