From 1f059e0a96abfb3686f697a581d6daf85fd18f0d Mon Sep 17 00:00:00 2001
From: Matt Spurrier <matthew@spurrier.com.au>
Date: Sat, 30 Mar 2024 22:00:40 +0800
Subject: [PATCH] quick update with global version access (#24)

* update for globally accesible version number

* update

* update

* add flag

* add flag

---------

Co-authored-by: Matt Spurrier <matthew@senseict.com.au>
Co-authored-by: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
---
 .goreleaser.yaml          | 5 ++---
 cmd/main.go               | 9 +++++++--
 internal/params/params.go | 6 +++---
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index a56219d..2048a0e 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -18,10 +18,9 @@ builds:
       - linux
     goarch:
       - amd64
-    ldflags:
-      - -s -w -X version.Version={{ .Tag }}
     mod_timestamp: "{{ .CommitTimestamp }}"
-
+    ldflags:
+      - -s -w -X github.com/HikariKnight/quickpassthrough/internal/version.Version={{.Version}}
 archives:
   - format: tar.gz
     # this name template makes the OS and Arch compatible with the results of `uname`.
diff --git a/cmd/main.go b/cmd/main.go
index fd13cda..eec1015 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"os"
 
 	internal "github.com/HikariKnight/quickpassthrough/internal"
 	downloader "github.com/HikariKnight/quickpassthrough/internal/ls_iommu_downloader"
@@ -13,9 +14,13 @@ func main() {
 	// Get all our arguments in 1 neat struct
 	pArg := params.NewParams()
 
+	// Display the version
 	if pArg.Flag["version"] {
-		fmt.Printf("Quickpassthrough version: %s\n", version.Version)
-	} else {
+		fmt.Printf("QuickPassthrough Version %s\n", version.Version)
+		os.Exit(0)
+	}
+
+	if !pArg.Flag["gui"] {
 		downloader.CheckLsIOMMU()
 		internal.Tui()
 	}
diff --git a/internal/params/params.go b/internal/params/params.go
index cd28cfa..d6b2aae 100644
--- a/internal/params/params.go
+++ b/internal/params/params.go
@@ -56,7 +56,7 @@ func NewParams() *Params {
 	// Add version flag
 	version := parser.Flag("v", "version", &argparse.Options{
 		Required: false,
-		Help:     "Display version",
+		Help:     "Display the version",
 	})
 
 	// Parse arguments
@@ -78,9 +78,9 @@ func NewParams() *Params {
 	}
 
 	// Add all parsed arguments to a struct for portability since we will use them all over the program
+	pArg.addFlag("gui", *gui)
 	pArg.addFlag("version", *version)
-	/*pArg.addFlag("gui", *gui)
-	pArg.addFlag("gpu", *gpu)
+	/*pArg.addFlag("gpu", *gpu)
 	pArg.addFlag("usb", *usb)
 	pArg.addFlag("nic", *nic)
 	pArg.addFlag("sata", *sata)