grokkit/cmd/root.go
Greg Gauthier 0aa806be70
Some checks failed
CI / Test (push) Failing after 25s
CI / Lint (push) Has been skipped
CI / Build (push) Has been skipped
feat(cmd): add AI documentation generation and command tests
- Implemented `grokkit docs` command for generating language-specific documentation comments (godoc, PEP 257, Doxygen, etc.) with previews, backups, and auto-apply option
- Extracted message builder functions for commit, history, pr-describe, and review commands
- Added comprehensive unit tests for all command message builders (commit_test.go, docs_test.go, history_test.go, lint_test.go, prdescribe_test.go, review_test.go)
- Enforced 70% test coverage threshold in CI workflow
- Added .golangci.yml configuration with linters like govet, errcheck, staticcheck
- Updated Makefile to include -race in tests and add help target
- Updated README.md with new docs command details, workflows, and quality features
- Added .claude/ to .gitignore
- Configured default model for docs command in config.go
2026-03-02 20:13:50 +00:00

68 lines
1.8 KiB
Go

package cmd
import (
"os"
"fmt"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/config"
"gmgauthier.com/grokkit/internal/logger"
"gmgauthier.com/grokkit/internal/version"
)
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)
}
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("grokkit version %s (commit %s)\\n", version.Version, version.Commit)
},
}
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)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(docsCmd)
// 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")
}