-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathfeedback_cmd.go
More file actions
121 lines (102 loc) · 3.02 KB
/
Copy pathfeedback_cmd.go
File metadata and controls
121 lines (102 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"context"
"encoding/json"
"fmt"
"time"
"github.com/spf13/cobra"
"go.uber.org/zap"
clioutput "github.com/smart-mcp-proxy/mcpproxy-go/internal/cli/output"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/config"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/telemetry"
)
var (
feedbackCategory string
feedbackEmail string
)
// GetFeedbackCommand returns the feedback submission command.
func GetFeedbackCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "feedback \"message\"",
Short: "Submit feedback (bug report, feature request, or general)",
Long: `Submit feedback to the MCPProxy team. Your message is sent to the
telemetry endpoint along with anonymous system context (version, OS, etc.).
Examples:
mcpproxy feedback "The search results could be more relevant" --category feature
mcpproxy feedback "Server crashes when adding OAuth server" --category bug
mcpproxy feedback "Great tool, thanks!" --category other --email me@example.com`,
Args: cobra.ExactArgs(1),
RunE: runFeedback,
}
cmd.Flags().StringVar(&feedbackCategory, "category", "other", "Feedback category: bug, feature, other")
cmd.Flags().StringVar(&feedbackEmail, "email", "", "Optional email for follow-up")
return cmd
}
func runFeedback(cmd *cobra.Command, args []string) error {
message := args[0]
// Validate inputs before sending
if !telemetry.ValidateCategory(feedbackCategory) {
return fmt.Errorf("invalid category %q: must be bug, feature, or other", feedbackCategory)
}
if err := telemetry.ValidateMessage(message); err != nil {
return fmt.Errorf("invalid message: %w", err)
}
cfg, err := loadFeedbackConfig()
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
logger, _ := zap.NewProduction()
defer logger.Sync()
cfgPath := config.GetConfigPath(cfg.DataDir)
svc := telemetry.New(cfg, cfgPath, version, Edition, logger)
req := &telemetry.FeedbackRequest{
Category: feedbackCategory,
Message: message,
Email: feedbackEmail,
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
resp, err := svc.SubmitFeedback(ctx, req)
if err != nil {
return fmt.Errorf("failed to submit feedback: %w", err)
}
format := clioutput.ResolveFormat(globalOutputFormat, globalJSONOutput)
switch format {
case "json":
data, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return err
}
fmt.Println(string(data))
default:
if resp.Success {
fmt.Println("Feedback submitted successfully!")
if resp.IssueURL != "" {
fmt.Printf("Track your feedback: %s\n", resp.IssueURL)
}
} else {
fmt.Printf("Feedback submission failed: %s\n", resp.Error)
}
}
return nil
}
func loadFeedbackConfig() (*config.Config, error) {
if configFile != "" {
cfg, err := config.LoadFromFile(configFile)
if err != nil {
return nil, err
}
if dataDir != "" {
cfg.DataDir = dataDir
}
return cfg, nil
}
cfg, err := config.Load()
if err != nil {
return nil, err
}
if dataDir != "" {
cfg.DataDir = dataDir
}
return cfg, nil
}