| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "parrot/internal/colors" |
| 7 | |
| 8 | "github.com/spf13/cobra" |
| 9 | ) |
| 10 | |
| 11 | var demoCmd = &cobra.Command{ |
| 12 | Use: "demo", |
| 13 | Short: "Show parrot personality and color demos", |
| 14 | Long: "Display examples of different personality levels and color schemes", |
| 15 | Run: runDemo, |
| 16 | } |
| 17 | |
| 18 | func init() { |
| 19 | rootCmd.AddCommand(demoCmd) |
| 20 | } |
| 21 | |
| 22 | func runDemo(cmd *cobra.Command, args []string) { |
| 23 | fmt.Println("🦜 Parrot Personality & Color Demo") |
| 24 | fmt.Println("═══════════════════════════════════") |
| 25 | fmt.Println() |
| 26 | |
| 27 | // Sample commands for demo |
| 28 | commands := []struct { |
| 29 | cmd string |
| 30 | cmdType string |
| 31 | exitCode string |
| 32 | }{ |
| 33 | {"git push origin main", "git", "1"}, |
| 34 | {"npm install express", "nodejs", "1"}, |
| 35 | {"docker run myapp", "docker", "125"}, |
| 36 | {"curl https://api.example.com", "http", "7"}, |
| 37 | } |
| 38 | |
| 39 | personalities := []string{"mild", "sarcastic", "savage"} |
| 40 | |
| 41 | for _, personality := range personalities { |
| 42 | fmt.Printf("🎭 %s Personality\n", personality) |
| 43 | fmt.Println("─────────────────────") |
| 44 | |
| 45 | for _, test := range commands { |
| 46 | // Use simple hardcoded responses for demo |
| 47 | var response string |
| 48 | switch personality { |
| 49 | case "mild": |
| 50 | response = getDemoResponse(test.cmdType, "mild") |
| 51 | case "sarcastic": |
| 52 | response = getDemoResponse(test.cmdType, "sarcastic") |
| 53 | case "savage": |
| 54 | response = getDemoResponse(test.cmdType, "savage") |
| 55 | } |
| 56 | |
| 57 | fmt.Printf("Command: %s\n", test.cmd) |
| 58 | fmt.Printf(" Simple: %s\n", colors.FormatParrotOutput(personality, response, false)) |
| 59 | fmt.Printf(" Enhanced: %s\n", colors.FormatParrotOutput(personality, response, true)) |
| 60 | fmt.Println() |
| 61 | } |
| 62 | |
| 63 | fmt.Println() |
| 64 | } |
| 65 | |
| 66 | // Color info |
| 67 | fmt.Printf("🎨 Colors enabled: %t\n", colors.ColorEnabled()) |
| 68 | if !colors.ColorEnabled() { |
| 69 | fmt.Println(" 💡 To enable colors, ensure you're in a terminal and NO_COLOR is not set") |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func getDemoResponse(cmdType, personality string) string { |
| 74 | responses := map[string]map[string]string{ |
| 75 | "mild": { |
| 76 | "git": "Git command failed. Maybe check your remote branch?", |
| 77 | "nodejs": "NPM seems unhappy. Try clearing your cache?", |
| 78 | "docker": "Container seems upset. Check your Dockerfile?", |
| 79 | "http": "Request didn't go through. Check the URL?", |
| 80 | "generic": "Command didn't work as expected. Check the syntax?", |
| 81 | }, |
| 82 | "sarcastic": { |
| 83 | "git": "Another git genius who forgot to pull first. Classic.", |
| 84 | "nodejs": "NPM install failed? Shocking! Nobody saw that coming.", |
| 85 | "docker": "Docker container more like docker DISASTER!", |
| 86 | "http": "404: Competence not found.", |
| 87 | "generic": "Wow, you managed to break something simple. Impressive!", |
| 88 | }, |
| 89 | "savage": { |
| 90 | "git": "Git rejected your code harder than everyone rejects you.", |
| 91 | "nodejs": "NPM refuses to install anything for someone this incompetent.", |
| 92 | "docker": "Your containers crash faster than your career prospects.", |
| 93 | "http": "The internet collectively rejected you. Impressive.", |
| 94 | "generic": "Your command failed harder than you failed at life.", |
| 95 | }, |
| 96 | } |
| 97 | |
| 98 | if personalityMap, exists := responses[personality]; exists { |
| 99 | if response, exists := personalityMap[cmdType]; exists { |
| 100 | return response |
| 101 | } |
| 102 | return personalityMap["generic"] |
| 103 | } |
| 104 | return "Error: Unknown personality" |
| 105 | } |