Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version information #7

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ release:
github:
owner: breml
name: bidichk
gomod:
proxy: true
31 changes: 31 additions & 0 deletions cmd/bidichk/main.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions pkg/bidichk/bidichk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/bidichk/version.go
Original file line number Diff line number Diff line change
@@ -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
}