Skip to content

Commit

Permalink
Fix interactive input params on pipeline start
Browse files Browse the repository at this point in the history
This will fix pipeline start throwing
error on interactive input params if
the params is of type array or string
without default value

Also fix array param with default input
as the question was incorrectly asked

Fix cloudfoundry#465
  • Loading branch information
piyush-garg authored and tekton-robot committed Nov 15, 2019
1 parent d6f2e11 commit 990cb81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
23 changes: 17 additions & 6 deletions pkg/cmd/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func (opt *startOptions) getInputResources(resources resourceOptionsFilter, pipe
return err
}
opt.Resources = append(opt.Resources, res.Name+"="+newres.Name)
continue
}
name := strings.TrimSpace(strings.Split(ans, " ")[0])
opt.Resources = append(opt.Resources, res.Name+"="+name)
Expand All @@ -247,14 +248,24 @@ func (opt *startOptions) getInputResources(resources resourceOptionsFilter, pipe

func (opt *startOptions) getInputParams(pipeline *v1alpha1.Pipeline) error {
for _, param := range pipeline.Spec.Params {
var ans string
var ans, ques, defaultValue string
ques = fmt.Sprintf("Value for param `%s` of type `%s`?", param.Name, param.Type)
input := &survey.Input{}
if param.Default != nil {
if param.Type == "string" {
defaultValue = param.Default.StringVal
} else {
defaultValue = strings.Join(param.Default.ArrayVal, ",")
}
ques = ques + fmt.Sprintf(" (Default is `%s`)", defaultValue)
input.Default = defaultValue
}
input.Message = ques

var qs = []*survey.Question{
{
Name: "pipeline param",
Prompt: &survey.Input{
Message: fmt.Sprintf("Value of param `%s` ? (Default is %s)", param.Name, param.Default.StringVal),
Default: param.Default.StringVal,
},
Name: "pipeline param",
Prompt: input,
},
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/cmd/pipeline/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func Test_start_pipeline_interactive(t *testing.T) {
tb.PipelineDeclaredResource("git-repo", "git"),
tb.PipelineParamSpec("pipeline-param", v1alpha1.ParamTypeString, tb.ParamSpecDefault("somethingdifferent")),
tb.PipelineParamSpec("rev-param", v1alpha1.ParamTypeString, tb.ParamSpecDefault("revision")),
tb.PipelineParamSpec("array-param", v1alpha1.ParamTypeArray, tb.ParamSpecDefault("revision1", "revision2")),
tb.PipelineTask("unit-test-1", "unit-test-task",
tb.PipelineTaskInputResource("workspace", "git-repo"),
tb.PipelineTaskOutputResource("image-to-use", "best-image"),
Expand Down Expand Up @@ -302,19 +303,27 @@ func Test_start_pipeline_interactive(t *testing.T) {
return err
}

if _, err := c.ExpectString("Value of param `pipeline-param` ?"); err != nil {
if _, err := c.ExpectString("Value for param `pipeline-param` of type `string`? (Default is `somethingdifferent`)"); err != nil {
return err
}

if _, err := c.SendLine("test"); err != nil {
return err
}

if _, err := c.ExpectString("Value of param `rev-param` ?"); err != nil {
if _, err := c.ExpectString("Value for param `rev-param` of type `string`? (Default is `revision`)"); err != nil {
return err
}

if _, err := c.SendLine("test2"); err != nil {
if _, err := c.SendLine("test1"); err != nil {
return err
}

if _, err := c.ExpectString("Value for param `array-param` of type `array`? (Default is `revision1,revision2`)"); err != nil {
return err
}

if _, err := c.SendLine("test2, test3"); err != nil {
return err
}

Expand Down

0 comments on commit 990cb81

Please sign in to comment.