diff --git a/cmd/relspec/main.go b/cmd/relspec/main.go index a5a50d9..87b12a7 100644 --- a/cmd/relspec/main.go +++ b/cmd/relspec/main.go @@ -6,6 +6,7 @@ import ( ) func main() { + printVersionHeader(os.Args[1:]) if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/cmd/relspec/root.go b/cmd/relspec/root.go index b2847ca..df46d41 100644 --- a/cmd/relspec/root.go +++ b/cmd/relspec/root.go @@ -13,6 +13,7 @@ var ( version = "dev" buildDate = "unknown" prisma7 bool + noVersion bool ) func init() { @@ -54,9 +55,6 @@ bidirectional conversion between various database schema formats. It reads database schemas from multiple sources (live databases, DBML, DCTX, DrawDB, etc.) and writes them to various formats (GORM, Bun, JSON, YAML, SQL, etc.).`, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - fmt.Printf("RelSpec %s (built: %s)\n\n", version, buildDate) - }, } func init() { @@ -72,4 +70,22 @@ func init() { rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(reportCmd) rootCmd.PersistentFlags().BoolVar(&prisma7, "prisma7", false, "Use Prisma 7 generator conventions when reading/writing Prisma schemas") + rootCmd.PersistentFlags().BoolVar(&noVersion, "no-version", false, "Suppress the RelSpec version header") +} + +// printVersionHeader prints the "RelSpec (built: )" banner +// that precedes all command output. It is invoked from main() before cobra +// parses/executes anything, so it runs even for --help and bare invocations. +// It is skipped when --no-version is present, or when the version subcommand +// is being run (which prints its own, more detailed output). +func printVersionHeader(args []string) { + for _, a := range args { + if a == "--no-version" { + return + } + } + if len(args) > 0 && args[0] == "version" { + return + } + fmt.Printf("RelSpec %s (built: %s)\n\n", version, buildDate) }