Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ci/linux/print-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if [[ "$CI" == "true" ]]; then
fi

# Show compiled version
$TARGET --version
$TARGET --version --verbose
2 changes: 1 addition & 1 deletion ci/windows/print-version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ if ($env:CI -eq "true") {
}

# Show compiled version
& $Target --version
& $Target --version --verbose
14 changes: 10 additions & 4 deletions cmd/bedrock_helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -172,7 +177,7 @@ func printUsage(fs *flag.FlagSet) {
bedrock_helper --resolve-pack <uuid> [--server-location <dir>] [--no-header]
bedrock_helper --install-all [--server-location <dir>] [--no-header]
bedrock_helper --uninstall-all [--server-location <dir>] [--no-header]
bedrock_helper --version
bedrock_helper --version [--verbose]
bedrock_helper --help
`
fmt.Fprintln(output, usageText)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions cmd/bedrock_helper/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -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
}