feat: add netssh version and --version
`netssh --version` used to be passed to ssh and failed with "unknown option -- -". Release builds now embed the tag via -X main.version; other builds fall back to the module build info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b46c4f74d
commit
786768ec53
3 files changed
+40
-2
No files matched your search
@@ -34,7 +34,7 @@ jobs:
|
|||||||
out="dist/netssh_${GOOS}_${GOARCH}"
|
out="dist/netssh_${GOOS}_${GOARCH}"
|
||||||
echo "→ $out"
|
echo "→ $out"
|
||||||
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH \
|
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH \
|
||||||
go build -trimpath -ldflags="-s -w" \
|
go build -trimpath -ldflags="-s -w -X main.version=${GITHUB_REF_NAME}" \
|
||||||
-o "$out" ./cmd/netssh
|
-o "$out" ./cmd/netssh
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -40,6 +40,7 @@ var managedSubcommands = map[string]bool{
|
|||||||
"completion": true,
|
"completion": true,
|
||||||
"__complete": true,
|
"__complete": true,
|
||||||
"help": true,
|
"help": true,
|
||||||
|
"version": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -49,6 +50,10 @@ func main() {
|
|||||||
runTUI()
|
runTUI()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if args[0] == "--version" {
|
||||||
|
fmt.Printf("netssh %s\n", buildVersion())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if managedSubcommands[args[0]] {
|
if managedSubcommands[args[0]] {
|
||||||
if err := rootCmd().Execute(); err != nil {
|
if err := rootCmd().Execute(); err != nil {
|
||||||
@@ -352,7 +357,7 @@ func rootCmd() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
root.AddCommand(notesCmd(), configureCmd(), searchCmd(), cacheCmd(), aliasCmd(), hookCmd(), shellInitCmd())
|
root.AddCommand(notesCmd(), configureCmd(), searchCmd(), cacheCmd(), aliasCmd(), hookCmd(), shellInitCmd(), versionCmd())
|
||||||
|
|
||||||
// cobra builds the "completion" command lazily; force init so we can extend it.
|
// cobra builds the "completion" command lazily; force init so we can extend it.
|
||||||
root.InitDefaultCompletionCmd()
|
root.InitDefaultCompletionCmd()
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// version is set at build time: -ldflags "-X main.version=v1.2.3".
|
||||||
|
var version = ""
|
||||||
|
|
||||||
|
// buildVersion falls back to the module version for `go install` builds.
|
||||||
|
func buildVersion() string {
|
||||||
|
if version != "" {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
|
||||||
|
return info.Main.Version
|
||||||
|
}
|
||||||
|
return "dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
func versionCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print the netssh version",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Fprintf(cmd.OutOrStdout(), "netssh %s\n", buildVersion())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user