/
parse.go
63 lines (50 loc) · 1.17 KB
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cmd
import (
"context"
"fmt"
"os"
"github.com/cloud66-oss/trackman/notifiers"
"github.com/cloud66-oss/trackman/utils"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
var parseCmd = &cobra.Command{
Use: "parse",
Short: "Parse the workflow and print the output",
Run: parseExec,
}
var (
parsingWorkflowFile string
)
func init() {
parseCmd.Flags().StringVarP(&parsingWorkflowFile, "file", "f", "", "workflow file to parse")
rootCmd.AddCommand(parseCmd)
}
func parseExec(cmd *cobra.Command, args []string) {
ctx := context.Background()
options := &utils.WorkflowOptions{
Notifier: notifiers.ConsoleNotify,
}
workflow, err := loadWorkflow(ctx, args, options, cmd)
if err != nil {
utils.PrintError(err.Error())
os.Exit(1)
}
// logger, err := utils.NewLogger(workflow.Logger, utils.NewLoggingContext(workflow, nil))
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
for _, step := range workflow.Steps {
if err = step.EnrichStep(ctx); err != nil {
utils.PrintError(err.Error())
os.Exit(1)
}
}
buff, err := yaml.Marshal(&workflow)
if err != nil {
utils.PrintError(err.Error())
os.Exit(1)
}
fmt.Println(string(buff))
}