Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
feat: add multiselect input (#769)
Browse files Browse the repository at this point in the history
* feat: add multiselect input

Signed-off-by: lucas.dittrich <[email protected]>

* refactor: turn the message of any selected item into a const

Signed-off-by: lucas.dittrich <[email protected]>

* test: add test for multiselect input type

Signed-off-by: lucas.dittrich <[email protected]>

* test: add multiselect input to runner's test mocks

Signed-off-by: lucas.dittrich <[email protected]>

* fix: fix lint

Signed-off-by: lucas.dittrich <[email protected]>

* fix: fix lint

Signed-off-by: lucas.dittrich <[email protected]>

* fix: fix lint in tests

Signed-off-by: lucas.dittrich <[email protected]>

* fix: fix lint in tests

Signed-off-by: lucas.dittrich <[email protected]>

* fix: fix lint in tests

Signed-off-by: lucas.dittrich <[email protected]>

* refactor: change the error return in the unmarshal in the loadItems function

Signed-off-by: lucas.dittrich <[email protected]>

* refactor: fix as per code review

Signed-off-by: lucas.dittrich <[email protected]>

* refactor: fix as per code review

Signed-off-by: lucas.dittrich <[email protected]>
  • Loading branch information
lucasdittrichzup authored Dec 14, 2020
1 parent 095d94a commit 25daaa0
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 52 deletions.
3 changes: 2 additions & 1 deletion pkg/commands/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func Build() *cobra.Command {
inputPassword := prompt.NewSurveyPassword()
inputList := prompt.NewSurveyList()
inputURL := prompt.NewSurveyURL()
inputMultiselect := prompt.NewSurveyMultiselect()

// deps
fileManager := stream.NewFileManager()
Expand Down Expand Up @@ -141,7 +142,7 @@ func Build() *cobra.Command {

postRunner := runner.NewPostRunner(fileManager, dirManager)

promptInManager := fprompt.NewInputManager(credResolver, fileManager, inputList, inputText, inputTextValidator, inputTextDefault, inputBool, inputPassword)
promptInManager := fprompt.NewInputManager(credResolver, fileManager, inputList, inputText, inputTextValidator, inputTextDefault, inputBool, inputPassword, inputMultiselect)
stdinInManager := stdin.NewInputManager(credResolver)
flagInManager := flag.NewInputManager(credResolver)
termInputTypes := formula.TermInputTypes{
Expand Down
1 change: 1 addition & 0 deletions pkg/formula/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
BoolType = "bool"
PassType = "password"
DynamicType = "dynamic"
Multiselect = "multiselect"
)

// addEnv Add environment variable to run formulas.
Expand Down
14 changes: 13 additions & 1 deletion pkg/formula/input/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
CachePattern = "%s/.%s.cache"
DefaultCacheNewLabel = "Type new value?"
DefaultCacheQty = 5
EmptyItems = "no items were provided. Please insert a list of items for the input %s in the config.json file of your formula"
)

type InputManager struct {
Expand All @@ -55,6 +56,7 @@ type InputManager struct {
prompt.InputTextValidator
prompt.InputBool
prompt.InputPassword
prompt.InputMultiselect
}

func NewInputManager(
Expand All @@ -66,6 +68,7 @@ func NewInputManager(
inDefValue input.InputTextDefault,
inBool prompt.InputBool,
inPass prompt.InputPassword,
inMultiselect prompt.InputMultiselect,
) formula.InputRunner {
return InputManager{
cred: cred,
Expand All @@ -76,6 +79,7 @@ func NewInputManager(
InputTextDefault: inDefValue,
InputBool: inBool,
InputPassword: inPass,
InputMultiselect: inMultiselect,
}
}

Expand Down Expand Up @@ -131,13 +135,21 @@ func (in InputManager) inputTypeToPrompt(items []string, i formula.Input) (strin
return in.loadInputValList(items, i)
}
return in.textValidator(i)

case input.DynamicType:
dl, err := in.dynamicList(i.RequestInfo)
if err != nil {
return "", err
}
return in.List(i.Label, dl, i.Tutorial)
case input.Multiselect:
if len(items) == 0 {
return "", fmt.Errorf(EmptyItems, i.Name)
}
sl, err := in.Multiselect(i)
if err != nil {
return "", err
}
return strings.Join(sl, "|"), nil
default:
return in.cred.Resolve(i.Type)
}
Expand Down
Loading

0 comments on commit 25daaa0

Please sign in to comment.