diff --git a/.goreleaser.yml b/.goreleaser.yml index af06ff2..0c2d0b5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -29,3 +29,5 @@ release: github: owner: breml name: bidichk +gomod: + proxy: true diff --git a/cmd/bidichk/main.go b/cmd/bidichk/main.go index 9579229..734446e 100644 --- a/cmd/bidichk/main.go +++ b/cmd/bidichk/main.go @@ -1,11 +1,42 @@ package main import ( + "fmt" + "os" + "path/filepath" + "runtime" + "runtime/debug" + "golang.org/x/tools/go/analysis/singlechecker" "github.com/breml/bidichk/pkg/bidichk" ) +var ( + version = "development" + commit = "" + date = "" +) + func main() { + bidichk.Version = buildVersion() + singlechecker.Main(bidichk.NewAnalyzer()) } + +func buildVersion() string { + result := fmt.Sprintf("%s version %s", filepath.Base(os.Args[0]), version) + + if commit != "" { + result = fmt.Sprintf("%s\ncommit: %s", result, commit) + } + if date != "" { + result = fmt.Sprintf("%s\nbuilt at: %s", result, date) + } + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { + result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum) + } + result = fmt.Sprintf("%s\ngoos: %s\ngoarch: %s", result, runtime.GOOS, runtime.GOARCH) + + return result +} diff --git a/pkg/bidichk/bidichk.go b/pkg/bidichk/bidichk.go index 70e708b..2e1e899 100644 --- a/pkg/bidichk/bidichk.go +++ b/pkg/bidichk/bidichk.go @@ -136,6 +136,7 @@ func NewAnalyzer() *analysis.Analyzer { a.Flags.Init("bidichk", flag.ExitOnError) a.Flags.Var(&bidichk.disallowedRunes, "disallowed-runes", disallowedDoc) + a.Flags.Var(versionFlag{}, "V", "print version and exit") return a } diff --git a/pkg/bidichk/version.go b/pkg/bidichk/version.go new file mode 100644 index 0000000..4cfc57d --- /dev/null +++ b/pkg/bidichk/version.go @@ -0,0 +1,19 @@ +package bidichk + +import ( + "fmt" + "os" +) + +var Version = "bidichk version dev" + +type versionFlag struct{} + +func (versionFlag) IsBoolFlag() bool { return true } +func (versionFlag) Get() interface{} { return nil } +func (versionFlag) String() string { return "" } +func (versionFlag) Set(s string) error { + fmt.Println(Version) + os.Exit(0) + return nil +}