From 56e9b2b4cfe450dcebd8090cd1221925d8f5ecaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=A0ar=C4=8Devi=C4=87?= Date: Tue, 16 Mar 2021 15:01:18 +0100 Subject: [PATCH] Refactor logs --- pkg/cli/evaluate.go | 2 ++ pkg/pipelines/model.go | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/cli/evaluate.go b/pkg/cli/evaluate.go index e8d1fe3..ce09ec3 100644 --- a/pkg/cli/evaluate.go +++ b/pkg/cli/evaluate.go @@ -26,6 +26,8 @@ var evaluateChangeInCmd = &cobra.Command{ output := fetchRequiredStringFlag(cmd, "output") logsPath := fetchRequiredStringFlag(cmd, "logs") + fmt.Printf("Evaluating change_in expressions in %s.\n\n", input) + logs.Open(logsPath) logs.SetCurrentPipelineFilePath(input) diff --git a/pkg/pipelines/model.go b/pkg/pipelines/model.go index a1cd2e4..124062f 100644 --- a/pkg/pipelines/model.go +++ b/pkg/pipelines/model.go @@ -2,6 +2,7 @@ package pipelines import ( "encoding/json" + "fmt" "time" gabs "github.com/Jeffail/gabs/v2" @@ -29,7 +30,13 @@ func (p *Pipeline) EvaluateChangeIns() error { return err } - for index := range list { + p.displayFoundWhenExpressions(list) + + fmt.Println("Evaluating when expressions.\n") + + for index, condition := range list { + fmt.Printf("%03d) %s\n", index+1, condition.Expression) + err := list[index].Eval() if err != nil { return err @@ -87,6 +94,17 @@ func (p *Pipeline) ExtractWhenConditions() ([]when.WhenExpression, error) { return extractor.Parse() } +func (p *Pipeline) displayFoundWhenExpressions(list []when.WhenExpression) { + fmt.Printf("Found when expressions at %d locations:\n\n", len(list)) + + for index, condition := range list { + fmt.Printf("%03d) Location: %+v\n", index+1, condition.Path) + fmt.Printf(" File: %s\n", condition.YamlPath) + fmt.Printf(" Expression: %s\n", condition.Expression) + fmt.Println() + } +} + func (p *Pipeline) ToJSON() ([]byte, error) { return json.Marshal(p.raw) }