Skip to content

Commit 4aff63f

Browse files
committed
fix: add missing version flag parsing
1 parent 6609d9a commit 4aff63f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cmd/nakedret/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package main
22

33
import (
4+
"flag"
5+
"fmt"
46
"go/build"
7+
"os"
8+
"path/filepath"
9+
"runtime"
10+
"runtime/debug"
511

612
"golang.org/x/tools/go/analysis/singlechecker"
713

@@ -23,8 +29,27 @@ func main() {
2329

2430
analyzer := nakedret.NakedReturnAnalyzer(nakedRet)
2531

32+
analyzer.Flags.Init("nakedret", flag.ExitOnError)
33+
2634
analyzer.Flags.UintVar(&nakedRet.MaxLength, "l", DefaultLines, "maximum number of lines for a naked return function")
2735
analyzer.Flags.BoolVar(&nakedRet.SkipTestFiles, "skip-test-files", DefaultSkipTestFiles, "set to true to skip test files")
36+
analyzer.Flags.Var(versionFlag{}, "V", "print version and exit")
2837

2938
singlechecker.Main(analyzer)
3039
}
40+
41+
type versionFlag struct{}
42+
43+
func (versionFlag) IsBoolFlag() bool { return true }
44+
func (versionFlag) Get() any { return nil }
45+
func (versionFlag) String() string { return "" }
46+
func (versionFlag) Set(s string) error {
47+
info, ok := debug.ReadBuildInfo()
48+
if ok {
49+
fmt.Fprintf(os.Stderr, "%s version %s built with %s (%s/%s)\n",
50+
filepath.Base(os.Args[0]), info.Main.Version, info.GoVersion, runtime.GOOS, runtime.GOARCH)
51+
}
52+
53+
os.Exit(0)
54+
return nil
55+
}

0 commit comments

Comments
 (0)