From 60b6ce224bf5cc18d65696c41bf9b79ca991661f Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Sun, 16 Aug 2026 11:35:38 -0400 Subject: [PATCH] Implemented verbose support for `--version`. --- .vscode/launch.json | 12 ++++++++++++ ci/linux/print-version.sh | 2 +- ci/windows/print-version.ps1 | 2 +- cmd/bedrock_helper/main.go | 14 ++++++++++---- cmd/bedrock_helper/version.go | 24 ++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a53f19f..58c81c3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,6 +32,18 @@ "--version" ] }, + { + "name": "bedrock_helper --version (verbose)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/cmd/bedrock_helper", + "cwd": "${workspaceFolder}", + "args": [ + "--version", + "--verbose" + ] + }, { "name": "bedrock_helper --help", "type": "go", diff --git a/ci/linux/print-version.sh b/ci/linux/print-version.sh index f09ea69..aab3639 100755 --- a/ci/linux/print-version.sh +++ b/ci/linux/print-version.sh @@ -30,4 +30,4 @@ if [[ "$CI" == "true" ]]; then fi # Show compiled version -$TARGET --version +$TARGET --version --verbose diff --git a/ci/windows/print-version.ps1 b/ci/windows/print-version.ps1 index 6dbae4f..b446553 100644 --- a/ci/windows/print-version.ps1 +++ b/ci/windows/print-version.ps1 @@ -26,4 +26,4 @@ if ($env:CI -eq "true") { } # Show compiled version -& $Target --version +& $Target --version --verbose diff --git a/cmd/bedrock_helper/main.go b/cmd/bedrock_helper/main.go index acf14b5..ee1a620 100644 --- a/cmd/bedrock_helper/main.go +++ b/cmd/bedrock_helper/main.go @@ -35,8 +35,13 @@ func printHeader() { fmt.Fprintf(os.Stdout, "bedrock_helper - install and manage Minecraft Bedrock add-on packs.\n") } -func printVersion() { +func printVersion(verbose bool) { fmt.Fprintf(os.Stdout, "Version %s.\n", GetProductVersionString()) + + if verbose { + verboseVersion := GetProductVersionVerboseString() + fmt.Fprintf(os.Stdout, "%s", verboseVersion) + } } func reportArgumentParsingError(format string, args ...any) { @@ -172,7 +177,7 @@ func printUsage(fs *flag.FlagSet) { bedrock_helper --resolve-pack [--server-location ] [--no-header] bedrock_helper --install-all [--server-location ] [--no-header] bedrock_helper --uninstall-all [--server-location ] [--no-header] - bedrock_helper --version + bedrock_helper --version [--verbose] bedrock_helper --help ` fmt.Fprintln(output, usageText) @@ -261,18 +266,19 @@ func run(args []string) int { // In case of parsing errors, the error will be printed before the flag library will call our custom fs.Usage(). // So we must print the application's header or version before doing the actual parsing. cfg.NoHeader = hasArgument("no-header") + cfg.Verbose = hasArgument("verbose") cfg.Version = hasArgument("version") // Should we only print the version ? if cfg.Version { - printVersion() + printVersion(cfg.Verbose) return 0 } // Print application header, unless specified not to if !cfg.NoHeader { printHeader() - printVersion() + printVersion(false) } var err error diff --git a/cmd/bedrock_helper/version.go b/cmd/bedrock_helper/version.go index f0bf723..77d8985 100644 --- a/cmd/bedrock_helper/version.go +++ b/cmd/bedrock_helper/version.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "runtime/debug" "strconv" @@ -245,3 +246,26 @@ func GetProductVersionString() string { msg := fmt.Sprintf("%s (%s) compiled on %s", p.Version, p.CommitHash, p.BuildDate) return msg } + +func GetProductVersionVerboseString() string { + info, ok := debug.ReadBuildInfo() + if !ok { + // Can't do better + return "" + } + + // Add detailed version string + msg := fmt.Sprintf("%s\n", info.Main.Version) + + // Serialize BuildSettings to json + jsonData, err := json.MarshalIndent(info.Settings, "", " ") + if err != nil { + msg += fmt.Sprintf("error: %v\n", err) + return msg + } + + // Add BuildSettings info to string + msg += fmt.Sprintf("%v\n", string(jsonData)) + + return msg +}