diff --git a/cmd/console/main.go b/cmd/console/main.go index 4457237..283107d 100644 --- a/cmd/console/main.go +++ b/cmd/console/main.go @@ -18,13 +18,20 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/Ronin48/NetworkInventoryAgent/cmd/console/tui" + "github.com/Ronin48/NetworkInventoryAgent/cmd/internal/runtime" "github.com/Ronin48/NetworkInventoryAgent/internal/sqlite" ) func main() { dbPath := flag.String("db", "inventory.db", "path to SQLite database file") + showVersion := flag.Bool("version", false, "print version and exit") flag.Parse() + if *showVersion { + fmt.Fprintf(os.Stdout, "console %s\n", runtime.VersionString()) + return + } + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() diff --git a/cmd/internal/runtime/runtime.go b/cmd/internal/runtime/runtime.go index 0be970d..7e440f0 100644 --- a/cmd/internal/runtime/runtime.go +++ b/cmd/internal/runtime/runtime.go @@ -38,10 +38,11 @@ import ( // of truth for both -version and any future User-Agent / metric exposition. var Version = "" -// versionString returns a printable version. Falls back to the VCS revision +// VersionString returns a printable version. Falls back to the VCS revision // embedded by `go build` when Version is empty, which covers the -// non-goreleaser local-build case. -func versionString() string { +// non-goreleaser local-build case. Exported so cmd/console (which doesn't +// go through Run) can produce the same -version output. +func VersionString() string { if Version != "" { return Version } @@ -80,7 +81,7 @@ func Run(opts Options) int { flag.Parse() if *showVersion { - fmt.Fprintf(os.Stdout, "%s %s\n", opts.Name, versionString()) + fmt.Fprintf(os.Stdout, "%s %s\n", opts.Name, VersionString()) return 0 }