package cmd import ( "fmt" "os" "github.com/kb-search/kb/internal/config" "github.com/spf13/cobra" ) // Version is set at build time via -ldflags. var Version = "dev" var ( flagEngine string flagFormat string flagAPIKey string ) var rootCmd = &cobra.Command{ Use: "kb", Short: "kb-search CLI client", Long: "A CLI client for the kb-search v2 engine API.", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if err := config.Load(); err != nil { return err } config.ApplyFlags(flagEngine, flagFormat, flagAPIKey) return nil }, } func init() { rootCmd.Version = Version rootCmd.PersistentFlags().StringVar(&flagEngine, "engine", "", "engine API URL") rootCmd.PersistentFlags().StringVar(&flagFormat, "format", "", "output format (human|json)") rootCmd.PersistentFlags().StringVar(&flagAPIKey, "api-key", "", "API key for authentication") } // Execute runs the root command. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }