Skip to content

Commit

Permalink
Fix dev version detection for remote go install
Browse files Browse the repository at this point in the history
  • Loading branch information
yalegko committed Jul 23, 2024
1 parent 00be57b commit 0c9d003
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/gon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func realMain() int {
v = strings.TrimLeft(v, "-")
if v == "v" || v == "version" {
if version == "" {
if v, err := parseRevision(); err == nil {
version = "commit " + v
if v, err := parseVersion(); err == nil && v != "" {
version = v
} else {
version = "dev"
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func printHelp(fs *flag.FlagSet) {
fs.PrintDefaults()
}

func parseRevision() (string, error) {
func parseVersion() (string, error) {
me, err := os.Executable()
if err != nil {
return "", fmt.Errorf("can't find myself: %w", err)
Expand All @@ -394,12 +394,13 @@ func parseRevision() (string, error) {
if err != nil {
return "", fmt.Errorf("no buildinfo: %w", err)
}
version := info.Main.Version
for _, s := range info.Settings {
if s.Key == "vcs.revision" {
return s.Value, nil
version += " commit " + s.Value
}
}
return "", fmt.Errorf("can't find build revision")
return version, nil
}

const help = `
Expand Down

0 comments on commit 0c9d003

Please sign in to comment.