Skip to content

Commit

Permalink
refactor: use debug BuildInfo for version if available
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Jul 26, 2023
1 parent 0774ee6 commit 9c73699
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/goose/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
_ "embed"
"errors"
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"runtime/debug"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -48,7 +50,11 @@ func main() {
}

if *versionFlag {
fmt.Printf("goose version: %s\n", version)
buildInfo, ok := debug.ReadBuildInfo()
if ok && buildInfo != nil && buildInfo.Main.Version != "" {
version = buildInfo.Main.Version
}
fmt.Printf("goose version: %s\n", strings.TrimSpace(version))
return
}
if *verbose {
Expand Down

0 comments on commit 9c73699

Please sign in to comment.