forked from devfile/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
126 lines (112 loc) · 3.19 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"fmt"
"os"
"reflect"
"strings"
devfilepkg "github.com/devfile/library/pkg/devfile"
"github.com/devfile/library/pkg/devfile/parser"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "updateSchema" {
ReplaceSchemaFile()
} else {
parserTest()
}
}
func parserTest() {
var args parser.ParserArgs
if len(os.Args) > 1 {
if strings.HasPrefix(os.Args[1], "http") {
args = parser.ParserArgs{
URL: os.Args[1],
}
} else {
args = parser.ParserArgs{
Path: os.Args[1],
}
}
fmt.Println("parsing devfile from " + os.Args[1])
} else {
args = parser.ParserArgs{
Path: "devfile.yaml",
}
fmt.Println("parsing devfile from ./devfile.yaml")
}
devfile, warning, err := devfilepkg.ParseDevfileAndValidate(args)
if err != nil {
fmt.Println(err)
} else {
if len(warning.Commands) > 0 || len(warning.Components) > 0 || len(warning.Projects) > 0 || len(warning.StarterProjects) > 0 {
fmt.Printf("top-level variables were not substituted successfully %+v\n", warning)
}
devdata := devfile.Data
if (reflect.TypeOf(devdata) == reflect.TypeOf(&v2.DevfileV2{})) {
d := devdata.(*v2.DevfileV2)
fmt.Printf("schema version: %s\n", d.SchemaVersion)
}
components, e := devfile.Data.GetComponents(common.DevfileOptions{})
if e != nil {
fmt.Printf("err: %v\n", err)
}
fmt.Printf("All component: \n")
for _, component := range components {
fmt.Printf("%s\n", component.Name)
}
fmt.Printf("All Exec commands: \n")
commands, e := devfile.Data.GetCommands(common.DevfileOptions{})
if e != nil {
fmt.Printf("err: %v\n", err)
}
for _, command := range commands {
if command.Exec != nil {
fmt.Printf("command %s is with kind: %s\n", command.Id, command.Exec.Group.Kind)
fmt.Printf("workingDir is: %s\n", command.Exec.WorkingDir)
}
}
fmt.Println("=========================================================")
compOptions := common.DevfileOptions{
Filter: map[string]interface{}{
"tool": "console-import",
"import": map[string]interface{}{
"strategy": "Dockerfile",
},
},
}
components, e = devfile.Data.GetComponents(compOptions)
if e != nil {
fmt.Printf("err: %v\n", err)
}
fmt.Printf("Container components applied filter: \n")
for _, component := range components {
if component.Container != nil {
fmt.Printf("%s\n", component.Name)
}
}
cmdOptions := common.DevfileOptions{
Filter: map[string]interface{}{
"tool": "odo",
},
}
fmt.Printf("Exec commands applied filter: \n")
commands, e = devfile.Data.GetCommands(cmdOptions)
if e != nil {
fmt.Printf("err: %v\n", err)
}
for _, command := range commands {
if command.Exec != nil {
fmt.Printf("command %s is with kind: %s", command.Id, command.Exec.Group.Kind)
fmt.Printf("workingDir is: %s\n", command.Exec.WorkingDir)
}
}
var err error
metadataAttr := devfile.Data.GetMetadata().Attributes
dockerfilePath := metadataAttr.GetString("alpha.build-dockerfile", &err)
if err != nil {
fmt.Printf("err: %v\n", err)
}
fmt.Printf("dockerfilePath: %s\n", dockerfilePath)
}
}