diff --git a/pkg/formula/formula.go b/pkg/formula/formula.go index f32710e7f..f56cd3752 100644 --- a/pkg/formula/formula.go +++ b/pkg/formula/formula.go @@ -50,6 +50,7 @@ type ( Cache Cache `json:"cache"` Condition Condition `json:"condition"` Tutorial string `json:"tutorial"` + Required *bool `json:"required"` } Cache struct { diff --git a/pkg/formula/runner/inputs.go b/pkg/formula/runner/inputs.go index e529ea3dc..d5e9a1203 100644 --- a/pkg/formula/runner/inputs.go +++ b/pkg/formula/runner/inputs.go @@ -134,7 +134,7 @@ func (in InputManager) fromPrompt(cmd *exec.Cmd, setup formula.Setup) error { if items != nil { inputVal, err = in.loadInputValList(items, input) } else { - validate := input.Default == "" + validate := isRequired(input) inputVal, err = in.Text(input.Label, validate, input.Tutorial) if inputVal == "" { @@ -209,7 +209,7 @@ func (in InputManager) loadInputValList(items []string, input formula.Input) (st } inputVal, err := in.List(input.Label, items, input.Tutorial) if inputVal == newLabel { - validate := len(input.Default) == 0 + validate := isRequired(input) inputVal, err = in.Text(input.Label, validate, input.Tutorial) if len(inputVal) == 0 { inputVal = input.Default @@ -256,6 +256,14 @@ func (in InputManager) resolveIfReserved(input formula.Input) (string, error) { return "", nil } +func isRequired(input formula.Input) bool { + if input.Required == nil { + return input.Default == "" + } + + return *input.Required +} + func (in InputManager) verifyConditional(cmd *exec.Cmd, input formula.Input) (bool, error) { if input.Condition.Variable == "" { return true, nil diff --git a/pkg/formula/runner/inputs_test.go b/pkg/formula/runner/inputs_test.go index d0bd4e434..b99fc0127 100644 --- a/pkg/formula/runner/inputs_test.go +++ b/pkg/formula/runner/inputs_test.go @@ -51,6 +51,12 @@ func TestInputManager_Inputs(t *testing.T) { "type": "text", "label": "Type : ", "default": "test" + }, + { + "name": "sample_text_2", + "type": "text", + "label": "Type : ", + "required": true }, { "name": "sample_list",