Skip to content

Commit

Permalink
dev: display version in verbose mode (#4771)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 29, 2024
1 parent 88f60c8 commit b9a67e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error
return err
}

c.log.Infof(c.buildInfo.String())

loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)

err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})
Expand Down
8 changes: 6 additions & 2 deletions pkg/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type BuildInfo struct {
Date string `json:"date"`
}

func (b BuildInfo) String() string {
return fmt.Sprintf("golangci-lint has version %s built with %s from %s on %s",
b.Version, b.GoVersion, b.Commit, b.Date)
}

type versionInfo struct {
Info BuildInfo
BuildInfo *debug.BuildInfo
Expand Down Expand Up @@ -92,7 +97,6 @@ func (c *versionCommand) execute(_ *cobra.Command, _ []string) error {
}

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

0 comments on commit b9a67e6

Please sign in to comment.