Files
ssh-netbox-wrapper/cmd/netssh/version.go
Sebastian UnterschützandClaude Opus 5.5 786768ec53 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>
2026-10-28 11:23:19 +01:00

34 lines
721 B
Go

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())
},
}
}