From 9c4a3dcb9f7670705a71a7594bd83a4563aab365 Mon Sep 17 00:00:00 2001 From: jettwang Date: Wed, 10 Jun 2026 00:28:42 +0800 Subject: [PATCH] feat: print version in --help and usage output Wire the build version (main.Version) into the app package and show a 'Version: ' line at the top of PrintUsage, so 'sshx --help' and the no-argument usage screen display the version alongside --version. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ cmd/sshx/main.go | 2 ++ internal/app/usage.go | 7 +++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f5c80..1cc7469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- `--help` and the no-argument usage screen now print the build version (`Version: `) + ## [0.0.10] - 2026-06-09 ### Added diff --git a/cmd/sshx/main.go b/cmd/sshx/main.go index 0d13e06..582dd4c 100644 --- a/cmd/sshx/main.go +++ b/cmd/sshx/main.go @@ -14,6 +14,8 @@ import ( var Version = "dev" func main() { + app.Version = Version + if handleVersionFlag(os.Args) { os.Exit(0) } diff --git a/internal/app/usage.go b/internal/app/usage.go index 7f3dcae..aabbd10 100644 --- a/internal/app/usage.go +++ b/internal/app/usage.go @@ -2,11 +2,14 @@ package app import "fmt" +// Version is the sshx build version, set by the main package at startup +// (injected via -ldflags). Defaults to "dev" for go test / go run builds. +var Version = "dev" + // PrintUsage prints the usage information for the sshx command. func PrintUsage() { + fmt.Printf("\nSSH & SFTP Remote Tool with Password Manager (Cross-Platform)\nVersion: %s\n", Version) fmt.Println(` -SSH & SFTP Remote Tool with Password Manager (Cross-Platform) - Usage: sshx -h= [options] # SSH mode sshx -h= [options] --upload= # SFTP upload