Skip to content

Commit

Permalink
Add the description to the survey prompt for credentials and parameters
Browse files Browse the repository at this point in the history
Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com>
  • Loading branch information
dgannon991 committed May 12, 2024
1 parent 7422f37 commit 0e5819b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/generator/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func genCredentialSet(namespace string, name string, creds map[string]bundle.Cre
sort.Strings(credentialNames)

for _, name := range credentialNames {
c, err := fn(name, surveyCredentials)
c, err := fn(name, creds[name].Description, surveyCredentials)
if err != nil {
return cs, err
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ const (
questionCommand = "shell command"
)

type generator func(name string, surveyType SurveyType) (secrets.SourceMap, error)
type generator func(name string, description string, surveyType SurveyType) (secrets.SourceMap, error)

func genEmptySet(name string, surveyType SurveyType) (secrets.SourceMap, error) {
func genEmptySet(name string, description string, surveyType SurveyType) (secrets.SourceMap, error) {
return secrets.SourceMap{
Name: name,
Source: secrets.Source{Hint: "TODO"},
}, nil
}

func genSurvey(name string, surveyType SurveyType) (secrets.SourceMap, error) {
func genSurvey(name string, description string, surveyType SurveyType) (secrets.SourceMap, error) {
if surveyType != surveyCredentials && surveyType != surveyParameters {
return secrets.SourceMap{}, fmt.Errorf("unsupported survey type: %s", surveyType)
}

// if there is a description, append the newline to the end of it
// this prevents empty descriptions adding new lines
if description != "" {
description += "\n"
}

// extra space-suffix to align question and answer. Unfortunately misaligns help text
sourceTypePrompt := &survey.Select{
Message: fmt.Sprintf("How would you like to set %s %q\n ", surveyType, name),
Message: fmt.Sprintf("How would you like to set %s %q\n%s ", surveyType, name, description),
Options: []string{questionSecret, questionValue, questionEnvVar, questionPath, questionCommand},
Default: "environment variable",
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func Test_genEmptySet(t *testing.T) {
Source: secrets.Source{Hint: "TODO"},
}

got, err := genEmptySet("emptyset", surveyParameters)
got, err := genEmptySet("emptyset", "", surveyParameters)
require.NoError(t, err)
require.Equal(t, expected, got)
}

func Test_genSurvey_unsupported(t *testing.T) {
got, err := genSurvey("myturtleset", SurveyType("turtles"))
got, err := genSurvey("myturtleset", "", SurveyType("turtles"))
require.EqualError(t, err, "unsupported survey type: turtles")
require.Equal(t, secrets.SourceMap{}, got)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/generator/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (opts *GenerateParametersOptions) genParameterSet(fn generator) (storage.Pa
if opts.Bundle.IsInternalParameter(name) {
continue
}
c, err := fn(name, surveyParameters)
c, err := fn(name, opts.Bundle.Parameters[name].Description, surveyParameters)
if err != nil {
return pset, err
}
Expand Down

0 comments on commit 0e5819b

Please sign in to comment.