Skip to content

Commit

Permalink
Refactor logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyasha committed Mar 16, 2021
1 parent 12a5232 commit 56e9b2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/cli/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 19 additions & 1 deletion pkg/pipelines/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pipelines

import (
"encoding/json"
"fmt"
"time"

gabs "github.com/Jeffail/gabs/v2"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 56e9b2b

Please sign in to comment.