- Refactor logger package to use Go's slog for JSON-structured logs - Add configurable log levels (debug, info, warn, error) via config and flags - Integrate logging across commands, git operations, and API client with metrics like timing and sizes - Update README with logging documentation and usage examples - Add global --debug and --verbose flags - Enhance tests for logger initialization, levels, and structured output
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"gmgauthier.com/grokkit/config"
|
|
"gmgauthier.com/grokkit/internal/logger"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "grokkit",
|
|
Short: "Personal Grok / xAI command-line toolkit",
|
|
Long: `A fast, native Go CLI for Grok. Chat, edit files, and supercharge your git workflow.`,
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
config.Load()
|
|
|
|
// Determine log level: flag > config > default
|
|
logLevel := config.GetLogLevel()
|
|
if debug, _ := cmd.Flags().GetBool("debug"); debug {
|
|
logLevel = "debug"
|
|
}
|
|
if verbose, _ := cmd.Flags().GetBool("verbose"); verbose {
|
|
logLevel = "info"
|
|
}
|
|
|
|
_ = logger.Init(logLevel) // Logging is optional, don't fail if it errors
|
|
logger.Info("grokkit starting", "command", cmd.Name(), "log_level", logLevel)
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(chatCmd)
|
|
rootCmd.AddCommand(editCmd)
|
|
rootCmd.AddCommand(reviewCmd)
|
|
rootCmd.AddCommand(commitMsgCmd)
|
|
rootCmd.AddCommand(commitCmd)
|
|
rootCmd.AddCommand(prDescribeCmd)
|
|
rootCmd.AddCommand(historyCmd)
|
|
rootCmd.AddCommand(agentCmd)
|
|
rootCmd.AddCommand(completionCmd)
|
|
|
|
// Add model flag to all commands
|
|
rootCmd.PersistentFlags().StringP("model", "m", "", "Grok model to use (overrides config)")
|
|
|
|
// Add logging flags
|
|
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug logging (logs to stderr and file)")
|
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging")
|
|
}
|