From 65eee86899e79bb97946dd54abd7f1eb8fd95fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=CC=87lker=20Go=CC=88ktug=CC=86=20O=CC=88ztu=CC=88rk?= Date: Mon, 26 Nov 2018 12:06:42 +0300 Subject: [PATCH] commands: handle task executions without inputs gracefully, closes #582 --- commands/service_execute.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/commands/service_execute.go b/commands/service_execute.go index df4fae211..e246e4761 100644 --- a/commands/service_execute.go +++ b/commands/service_execute.go @@ -141,15 +141,20 @@ func (c *serviceExecuteCmd) getData(taskKey string, s *coreapi.Service, dataStru return string(b), err } - if c.jsonFile == "" { - if survey.AskOne(&survey.Input{Message: "Enter the filepath to the inputs"}, &c.jsonFile, nil) != nil { - return "", errors.New("no filepath given") + // see if task has no inputs. + for _, task := range s.Tasks { + if task.Key == taskKey { + if len(task.Inputs) == 0 { + return "{}", nil + } + break } } - // still no answer then return empty json object if c.jsonFile == "" { - return "{}", nil + if survey.AskOne(&survey.Input{Message: "Enter the filepath to the inputs"}, &c.jsonFile, nil) != nil { + return "", errors.New("no filepath given") + } } content, err := xjson.ReadFile(c.jsonFile)