Skip to content

Commit

Permalink
Add multiline prompt config support (#216)
Browse files Browse the repository at this point in the history
* add multiline response support

* update mdlint with present docker image

---------

Co-authored-by: Gabriel Saliev <[email protected]>
  • Loading branch information
gabbigum and Gabriel Saliev authored Oct 16, 2024
1 parent 7278b25 commit 2641f40
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions component/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type PromptConfig struct {
// Sensitive information.
Sensitive bool

// Multiline response
Multiline bool

// Help for the prompt.
Help string
}
Expand Down Expand Up @@ -90,6 +93,13 @@ func buildPrompt(p *PromptConfig, enableMultiSelect bool) survey.Prompt {
Help: p.Help,
}
}
if p.Multiline {
return &survey.Multiline{
Message: p.Message,
Default: p.Default,
Help: p.Help,
}
}
return &survey.Input{
Message: p.Message,
Default: p.Default,
Expand Down
16 changes: 16 additions & 0 deletions component/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ func Test_translatePromptConfig_Sensitive(t *testing.T) {
assert.True(ok)
}

func Test_PromptConfig_WithMultilineResponse(t *testing.T) {
assert := assert.New(t)

promptConfig := PromptConfig{
Message: "Write me a poem",
Default: "Foo bar,\nbar foo",
Sensitive: false,
Help: "Help will be given to those who need it",
Multiline: true,
}
prompt := buildPrompt(&promptConfig, true)
assert.NotNil(prompt)
_, ok := prompt.(*survey.Multiline)
assert.True(ok)
}

func Test_translatePromptConfig_OptionsSelect(t *testing.T) {
assert := assert.New(t)

Expand Down
2 changes: 1 addition & 1 deletion hack/check/check-mdlint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.."
# Additional configuration can be found in the .markdownlintrc file at
# the root of the repo.
docker run --rm -v "$(pwd)":/build \
gcr.io/cluster-api-provider-vsphere/extra/mdlint:0.23.2 /md/lint \
ghcr.io/vmware-tanzu/tanzu-cli/ci-images/mdlint:0.23.2 /md/lint \
-i **/CHANGELOG.md .

0 comments on commit 2641f40

Please sign in to comment.