-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from breml/issue_10
Add version information
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ release: | |
github: | ||
owner: breml | ||
name: errchkjson | ||
gomod: | ||
proxy: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"runtime/debug" | ||
|
||
"github.com/breml/errchkjson" | ||
|
||
"golang.org/x/tools/go/analysis/singlechecker" | ||
) | ||
|
||
var ( | ||
version = "development" | ||
commit = "" | ||
date = "" | ||
) | ||
|
||
func main() { | ||
errchkjson.Version = buildVersion() | ||
|
||
singlechecker.Main(errchkjson.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package errchkjson | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var Version = "errchkjson 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 | ||
} |