From e0abd1a7a807007aefd30d8c108490c55771a965 Mon Sep 17 00:00:00 2001 From: Anuj Chaudhari Date: Tue, 5 Nov 2024 09:53:11 -0800 Subject: [PATCH] Add multiline prompt config support (#217) * add multiline response support * update mdlint with present docker image --------- Co-authored-by: Gabriel Saliev --- component/prompt.go | 10 ++++++++++ component/prompt_test.go | 16 ++++++++++++++++ hack/check/check-mdlint.sh | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/component/prompt.go b/component/prompt.go index e5b26648c..951b50949 100644 --- a/component/prompt.go +++ b/component/prompt.go @@ -29,6 +29,9 @@ type PromptConfig struct { // Sensitive information. Sensitive bool + // Multiline response + Multiline bool + // Help for the prompt. Help string } @@ -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, diff --git a/component/prompt_test.go b/component/prompt_test.go index 60b60d155..2a068d7ef 100644 --- a/component/prompt_test.go +++ b/component/prompt_test.go @@ -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) diff --git a/hack/check/check-mdlint.sh b/hack/check/check-mdlint.sh index 550b41ad3..de1cccf1d 100755 --- a/hack/check/check-mdlint.sh +++ b/hack/check/check-mdlint.sh @@ -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 .