Go · 2005 bytes Raw Blame History
1 package cmd
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7
8 "parrot/internal/config"
9
10 "github.com/spf13/cobra"
11 )
12
13 var configCmd = &cobra.Command{
14 Use: "config",
15 Short: "Manage parrot configuration",
16 Long: "Create and manage parrot configuration files",
17 }
18
19 var configInitCmd = &cobra.Command{
20 Use: "init [path]",
21 Short: "Create a sample configuration file",
22 Long: "Create a sample configuration file with default values",
23 Args: cobra.MaximumNArgs(1),
24 Run: initConfig,
25 }
26
27 func init() {
28 configCmd.AddCommand(configInitCmd)
29 rootCmd.AddCommand(configCmd)
30 }
31
32 func initConfig(cmd *cobra.Command, args []string) {
33 var configPath string
34
35 if len(args) > 0 {
36 // User specified path
37 configPath = args[0]
38 } else {
39 // Use default user config path
40 configDir, err := os.UserConfigDir()
41 if err != nil {
42 fmt.Printf("❌ Error getting config directory: %v\n", err)
43 return
44 }
45 configPath = filepath.Join(configDir, "parrot", "config.toml")
46 }
47
48 // Check if config already exists
49 if _, err := os.Stat(configPath); err == nil {
50 fmt.Printf("❌ Configuration file already exists at: %s\n", configPath)
51 fmt.Println(" Remove it first if you want to recreate it.")
52 return
53 }
54
55 // Create the config file
56 if err := config.CreateSampleConfig(configPath); err != nil {
57 fmt.Printf("❌ Error creating config file: %v\n", err)
58 return
59 }
60
61 fmt.Printf("✅ Created configuration file at: %s\n", configPath)
62 fmt.Println("\n💡 Next steps:")
63 fmt.Println(" 1. Edit the config file to add your API key:")
64 fmt.Printf(" api_key = \"your-openai-api-key-here\"\n")
65 fmt.Println(" 2. Test with: parrot status")
66 fmt.Println(" 3. Try: parrot mock \"git push\" \"1\"")
67
68 fmt.Println("\n🔧 Configuration options:")
69 fmt.Println(" • API providers: openai, anthropic, custom")
70 fmt.Println(" • Personalities: mild, sarcastic, savage")
71 fmt.Println(" • Local models: phi3.5:3.8b, llama3.2:3b")
72 fmt.Println(" • Environment variables: PARROT_API_KEY, PARROT_DEBUG")
73 }