diff --git a/app/app.go b/app/app.go index c6023a1..5193e6e 100644 --- a/app/app.go +++ b/app/app.go @@ -28,13 +28,13 @@ type TlmApp struct { suggestModelfile string } -func New(version string) *TlmApp { +func New(version, buildSha string) *TlmApp { con := config.New() con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - sug := suggest.New(o, suggestModelfile) - exp := explain.New(o, explainModelfile) + sug := suggest.New(o) + exp := explain.New(o) ins := install.New(o, suggestModelfile, explainModelfile) cliApp := &cli.App{ @@ -59,7 +59,7 @@ func New(version string) *TlmApp { Aliases: []string{"v"}, Usage: "Prints tlm version.", Action: func(c *cli.Context) error { - fmt.Printf("tlm %s (%s/%s)", version, runtime.GOOS, runtime.GOARCH) + fmt.Printf("tlm %s %s on %s/%s", version, buildSha, runtime.GOOS, runtime.GOARCH) return nil }, }, diff --git a/build.ps1 b/build.ps1 index 78d7650..ed3bf0d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -17,13 +17,14 @@ New-Item -ItemType Directory -Path "dist" # Build Function (Helper) Function Build-Target($os, $version, $arch) { $outputName = "${appName}_${version}_${os}_${arch}" + $sha1 = (git rev-parse --short HEAD).Trim() if ($os -eq "windows") { $outputName += ".exe" } Write-Output "Building for $os/$arch (version: $version) -> $outputName" # Invokes the Go toolchain (assumes it's in the PATH) - go build -o "dist/$version/$outputName" "main.go" + go build -o "dist/$version/$outputName" -ldflags "-X main.sha1ver=$sha1" "main.go" } # Build for each target OS diff --git a/build.sh b/build.sh index ef4dc88..cb96466 100644 --- a/build.sh +++ b/build.sh @@ -6,6 +6,7 @@ build() { app_name=$2 version=$3 arch=$4 + sha1=$(git rev-parse --short HEAD | tr -d '\n') # Determine output filename with optional .exe extension output_name="${app_name}_${version}_${os}_${arch}" @@ -14,7 +15,7 @@ build() { fi echo "Building for $os/$arch (version: $version) -> $output_name" - CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" main.go + CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" -ldflags "-X main.sha1ver=$sha1" main.go } # Operating systems to target diff --git a/explain/explain.go b/explain/explain.go index 009a523..5d5b7b9 100644 --- a/explain/explain.go +++ b/explain/explain.go @@ -6,11 +6,10 @@ import ( type Explain struct { api *ollama.Client - modelfile string modelfileName string } -func New(api *ollama.Client, modelfile string) *Explain { - e := &Explain{api: api, modelfile: modelfile, modelfileName: "explain:7b"} +func New(api *ollama.Client) *Explain { + e := &Explain{api: api, modelfileName: "explain:7b"} return e } diff --git a/main.go b/main.go index 27f9299..c5c10b6 100644 --- a/main.go +++ b/main.go @@ -10,9 +10,10 @@ import ( //go:embed VERSION var version string +var sha1ver string func main() { - tlm := app.New(version) + tlm := app.New(version, sha1ver) if err := tlm.App.Run(os.Args); err != nil { log.Fatal(err) } diff --git a/suggest/suggest.go b/suggest/suggest.go index c15df9d..98fa9cc 100644 --- a/suggest/suggest.go +++ b/suggest/suggest.go @@ -6,10 +6,9 @@ import ( type Suggest struct { api *ollama.Client - modelfile string modelfileName string } -func New(api *ollama.Client, modelfile string) *Suggest { - return &Suggest{api: api, modelfile: modelfile, modelfileName: "suggest:7b"} +func New(api *ollama.Client) *Suggest { + return &Suggest{api: api, modelfileName: "suggest:7b"} }