From 9a8e1002cd27e979c1a1a9c487c5cc820a91be41 Mon Sep 17 00:00:00 2001 From: Matt Spurrier Date: Sat, 30 Mar 2024 21:24:30 +0800 Subject: [PATCH 1/8] update for globally accesible version number --- .goreleaser.yaml | 4 ++-- cmd/main.go | 8 ++++++++ internal/version/version.go | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 internal/version/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 0091b22..8958d8b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,11 +16,11 @@ builds: - CGO_ENABLED=0 goos: - linux - goarch: - amd64 mod_timestamp: "{{ .CommitTimestamp }}" - + ldflags: + - -s -w -X 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 5973bf6..661b272 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,15 +1,23 @@ package main import ( + "fmt" + internal "github.com/HikariKnight/quickpassthrough/internal" downloader "github.com/HikariKnight/quickpassthrough/internal/ls_iommu_downloader" "github.com/HikariKnight/quickpassthrough/internal/params" + "github.com/HikariKnight/quickpassthrough/internal/version" ) func main() { // Get all our arguments in 1 neat struct pArg := params.NewParams() + // Display the version + if p.Arg.Flag["version"] { + fmt.Printf("QuickPassthrough Version %s\n", version.Version) + } + if !pArg.Flag["gui"] { downloader.CheckLsIOMMU() internal.Tui() diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..c50b3ee --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,3 @@ +package version + +type Version string From 114ed596db7a22f9c50daa7561110f1c3cb4b37d Mon Sep 17 00:00:00 2001 From: Matt Spurrier Date: Sat, 30 Mar 2024 21:28:25 +0800 Subject: [PATCH 2/8] update --- cmd/main.go | 2 +- internal/version/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 661b272..f7517ed 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,7 +6,7 @@ import ( internal "github.com/HikariKnight/quickpassthrough/internal" downloader "github.com/HikariKnight/quickpassthrough/internal/ls_iommu_downloader" "github.com/HikariKnight/quickpassthrough/internal/params" - "github.com/HikariKnight/quickpassthrough/internal/version" + version "github.com/HikariKnight/quickpassthrough/internal/version" ) func main() { diff --git a/internal/version/version.go b/internal/version/version.go index c50b3ee..7f6928e 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,3 +1,3 @@ package version -type Version string +var Version string From 4ac207cf8234368c9a386f45eb9906f59f66f005 Mon Sep 17 00:00:00 2001 From: Matt Spurrier Date: Sat, 30 Mar 2024 21:30:20 +0800 Subject: [PATCH 3/8] update --- cmd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index f7517ed..7798324 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,7 +14,7 @@ func main() { pArg := params.NewParams() // Display the version - if p.Arg.Flag["version"] { + if pArg.Flag["version"] { fmt.Printf("QuickPassthrough Version %s\n", version.Version) } From feeae00f74643c955a260c59d98341ead5b24e47 Mon Sep 17 00:00:00 2001 From: Matt Spurrier Date: Sat, 30 Mar 2024 21:36:03 +0800 Subject: [PATCH 4/8] add flag --- internal/params/params.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/params/params.go b/internal/params/params.go index dab85bb..2c92d69 100644 --- a/internal/params/params.go +++ b/internal/params/params.go @@ -53,6 +53,11 @@ func NewParams() *Params { Help: "Launch GUI (placeholder for now)", }) + version := parser.Flag("v", "version", &argparse.Options{ + Required: false, + Help: "Display the version", + }) + // Parse arguments err := parser.Parse(os.Args) if err != nil { @@ -73,6 +78,7 @@ 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("gpu", *gpu) pArg.addFlag("usb", *usb) pArg.addFlag("nic", *nic) From 317c550cf2b4ac7c149651a62f1f0f920a93d66b Mon Sep 17 00:00:00 2001 From: Matt Spurrier Date: Sat, 30 Mar 2024 21:45:08 +0800 Subject: [PATCH 5/8] add flag --- .goreleaser.yaml | 2 +- cmd/main.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8958d8b..fd53965 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -20,7 +20,7 @@ builds: - amd64 mod_timestamp: "{{ .CommitTimestamp }}" ldflags: - - -s -w -X version.Version={{.Version}} + - -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 7798324..eec1015 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "os" internal "github.com/HikariKnight/quickpassthrough/internal" downloader "github.com/HikariKnight/quickpassthrough/internal/ls_iommu_downloader" "github.com/HikariKnight/quickpassthrough/internal/params" - version "github.com/HikariKnight/quickpassthrough/internal/version" + "github.com/HikariKnight/quickpassthrough/internal/version" ) func main() { @@ -16,6 +17,7 @@ func main() { // Display the version if pArg.Flag["version"] { fmt.Printf("QuickPassthrough Version %s\n", version.Version) + os.Exit(0) } if !pArg.Flag["gui"] { From 2e181f9e3cc2f6bddf18d45f64e4fd92d645705e Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:56:37 +0100 Subject: [PATCH 6/8] remove the old ldflags line --- .goreleaser.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f8c56c2..2048a0e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,8 +18,6 @@ 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}} From a48ae7716f229a00cc41625e6a488efb386bc027 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:58:18 +0100 Subject: [PATCH 7/8] remove duplicate version flag --- internal/params/params.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/params/params.go b/internal/params/params.go index b3b78aa..d6b2aae 100644 --- a/internal/params/params.go +++ b/internal/params/params.go @@ -54,11 +54,6 @@ func NewParams() *Params { })*/ // Add version flag - version := parser.Flag("v", "version", &argparse.Options{ - Required: false, - Help: "Display version", - }) - version := parser.Flag("v", "version", &argparse.Options{ Required: false, Help: "Display the version", From 009a05fa1de7e740e546dde71bc00c381d4e35f7 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:59:29 +0100 Subject: [PATCH 8/8] Adding back the comment useful for me --- internal/version/version.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/version/version.go b/internal/version/version.go index 7f6928e..cfa579a 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,3 +1,4 @@ package version +// This is automatically set in CI using -ldflags="-X github.com/HikariKnight/quickpassthrough/internal/version.Version=${TAG}" as a build argument var Version string