Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ const (
JfrogCliGithubToken = ` JFROG_CLI_GITHUB_TOKEN
[Default: None]
Specifies the GitHub token to be used for cli version check on Github repository.`

JfrogCliHideSurvey = ` JFROG_CLI_HIDE_SURVEY
[Default: false]
Set to true to hide the survey link that appears after successful command execution.`
)

var (
Expand Down Expand Up @@ -148,7 +152,8 @@ func GetGlobalEnvVars() string {
JfrogCliAvoidNewVersionWarning,
JfrogCliCommandSummaryOutputDirectory,
JfrogSecurityCliAnalyzerManagerVersion,
JfrogCliGithubToken)
JfrogCliGithubToken,
JfrogCliHideSurvey)
}

func CreateEnvVars(envVars ...string) string {
Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,22 @@ func execMain() error {

err = app.Run(args)
logTraceIdOnFailure(err)

if err == nil {
displaySurveyLinkIfNeeded()
}

return err
}

// displaySurveyLinkIfNeeded checks if the survey should be hidden based on the JFROG_CLI_HIDE_SURVEY environment variable
func displaySurveyLinkIfNeeded() {
if cliutils.ShouldHideSurveyLink() {
return
}
fmt.Fprintln(os.Stderr, "\n💬 Help us improve JFrog CLI! \033]8;;https://www.surveymonkey.com/r/JFCLICLI\033\\https://www.surveymonkey.com/r/JFCLICLI\033]8;;\033\\")
}

func runNativeImplementation(ctx *cli.Context) error {
clientlog.Debug("Starting native implementation...")

Expand Down
1 change: 1 addition & 0 deletions utils/cliutils/cli_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ const (
JfrogCliAvoidNewVersionWarning = "JFROG_CLI_AVOID_NEW_VERSION_WARNING"
//#nosec G101
JfrogCliGithubToken = "JFROG_CLI_GITHUB_TOKEN"
JfrogCliHideSurvey = "JFROG_CLI_HIDE_SURVEY"
)
6 changes: 6 additions & 0 deletions utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,9 @@ func GetJFrogApplicationKey(c *cli.Context) string {
}
return applicationKey
}

// ShouldHideSurveyLink checks if the survey should be hidden based on the JFROG_CLI_HIDE_SURVEY environment variable
// Returns true if the survey should be hidden (env var is "true"), false otherwise
func ShouldHideSurveyLink() bool {
return os.Getenv(JfrogCliHideSurvey) == "true"
}
39 changes: 39 additions & 0 deletions utils/cliutils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,42 @@ func (t *redirectingTransport) RoundTrip(req *http.Request) (*http.Response, err
// For all other requests, use the base transport
return t.baseTransport.RoundTrip(req)
}

// TestGetHasDisplayedSurveyLink tests the survey link environment variable check with parametrized test cases
func TestGetHasDisplayedSurveyLink(t *testing.T) {
testCases := []struct {
name string
envValue string
shouldHide bool
}{
{
name: "env_var_not_set",
envValue: "", // This will be handled by unsetting the env var
shouldHide: false,
},
{
name: "env_var_true",
envValue: "true",
shouldHide: true,
},
{
name: "env_var_bad_input",
envValue: "garbage",
shouldHide: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv(JfrogCliHideSurvey, tc.envValue)

shouldHide := ShouldHideSurveyLink()

if tc.shouldHide {
assert.True(t, shouldHide, "Expected survey to be hidden for test case: %s", tc.name)
} else {
assert.False(t, shouldHide, "Expected survey to not be hidden for test case: %s", tc.name)
}
})
}
}