3 Commits

Author SHA1 Message Date
f4ddb45fd2 don't log.Fatal if we can't read version... 2025-06-19 02:21:12 +01:00
cad1585975 add versionFromBuild 2025-06-19 02:12:56 +01:00
4139c4b291 fix regression reading build info 2025-06-19 02:07:25 +01:00

15
main.go
View File

@@ -4,6 +4,7 @@ package main
import ( import (
"context" "context"
"os" "os"
"runtime/debug"
"strings" "strings"
"github.com/charmbracelet/fang" "github.com/charmbracelet/fang"
@@ -56,7 +57,19 @@ func init() {
// main is the entry point of the application. // main is the entry point of the application.
// It executes the root command and handles any errors. // It executes the root command and handles any errors.
func main() { func main() {
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(version)); err != nil { if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(versionFromBuild())); err != nil {
os.Exit(1) os.Exit(1)
} }
} }
func versionFromBuild() string {
if version == "" {
info, ok := debug.ReadBuildInfo()
if !ok {
return "(unable to read version)"
}
version = strings.Split(info.Main.Version, "-")[0]
}
return version
}