-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
10e1993
commit 74dcd8a
Showing
13 changed files
with
151 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package feedback | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
cliv1 "github.com/confluentinc/ccloud-sdk-go-v2/cli/v1" | ||
|
||
pcmd "github.com/confluentinc/cli/internal/pkg/cmd" | ||
"github.com/confluentinc/cli/internal/pkg/form" | ||
"github.com/confluentinc/cli/internal/pkg/output" | ||
pversion "github.com/confluentinc/cli/internal/pkg/version" | ||
) | ||
|
||
type command struct { | ||
*pcmd.AuthenticatedCLICommand | ||
} | ||
|
||
func New(prerunner pcmd.PreRunner) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "feedback", | ||
Short: fmt.Sprintf("Submit feedback for the %s.", pversion.FullCLIName), | ||
Args: cobra.NoArgs, | ||
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, | ||
} | ||
|
||
c := &command{AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner)} | ||
cmd.RunE = c.feedback | ||
|
||
return cmd | ||
} | ||
|
||
func (c *command) feedback(_ *cobra.Command, _ []string) error { | ||
feedback, err := getFeedback(form.NewPrompt()) | ||
if err != nil { | ||
return err | ||
} | ||
if feedback != "" { | ||
feedbackReq := cliv1.CliV1Feedback{Content: cliv1.PtrString(feedback)} | ||
if err := c.V2Client.CreateCliFeedback(feedbackReq); err != nil { | ||
return err | ||
} | ||
output.Println("Thanks for your feedback.") | ||
} | ||
return nil | ||
} | ||
|
||
func getFeedback(prompt form.Prompt) (string, error) { | ||
f := form.New( | ||
form.Field{ | ||
ID: "feedback", | ||
Prompt: "Enter feedback", | ||
}, | ||
form.Field{ | ||
ID: "proceed", | ||
Prompt: "Please confirm that your feedback does not contain any sensitive information", | ||
IsYesOrNo: true, | ||
}, | ||
) | ||
if err := f.Prompt(prompt); err != nil { | ||
return "", err | ||
} | ||
feedback := strings.TrimSpace(f.Responses["feedback"].(string)) | ||
if !f.Responses["proceed"].(bool) { | ||
output.Println("Your feedback was not submitted.") | ||
return "", nil | ||
} | ||
return feedback, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package test | ||
|
||
func (s *CLITestSuite) TestFeedback() { | ||
tests := []CLITest{ | ||
{args: "feedback", fixture: "feedback/no-confirm.golden", input: "This CLI is great!\nn\n"}, | ||
{args: "feedback", fixture: "feedback/received.golden", input: "This CLI is great!\ny\n"}, | ||
{args: "feedback", exitCode: 1, fixture: "feedback/too-long.golden", input: "Lorem ipsum dolor sit amet. Qui amet molestiae eum eaque perferendis\ny\n"}, | ||
} | ||
|
||
for _, test := range tests { | ||
test.login = "cloud" | ||
s.runIntegrationTest(test) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Submit feedback for the Confluent CLI. | ||
|
||
Usage: | ||
confluent feedback [flags] | ||
|
||
Global Flags: | ||
-h, --help Show help for this command. | ||
--unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
-v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enter feedback: Please confirm that your feedback does not contain any sensitive information (y/n): Your feedback was not submitted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enter feedback: Please confirm that your feedback does not contain any sensitive information (y/n): Thanks for your feedback. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enter feedback: Please confirm that your feedback does not contain any sensitive information (y/n): Error: feedback exceeds the maximum length: 403 Forbidden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package testserver | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
cliv1 "github.com/confluentinc/ccloud-sdk-go-v2/cli/v1" | ||
) | ||
|
||
// Handler for: /cli/v1/feedbacks | ||
func handleFeedbacks(t *testing.T) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
req := new(cliv1.CliV1Feedback) | ||
err := json.NewDecoder(r.Body).Decode(req) | ||
require.NoError(t, err) | ||
if len(*req.Content) > 20 { | ||
w.WriteHeader(http.StatusForbidden) | ||
err = writeErrorJson(w, "feedback exceeds the maximum length") | ||
require.NoError(t, err) | ||
} else { | ||
w.WriteHeader(http.StatusNoContent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters