diff --git a/pkg/hal/cli/component/create.go b/pkg/hal/cli/component/create.go index ec6189c..b4cd6a1 100644 --- a/pkg/hal/cli/component/create.go +++ b/pkg/hal/cli/component/create.go @@ -1,6 +1,7 @@ package component import ( + "encoding/json" "fmt" "github.com/spf13/cobra" "halkyon.io/api/component/v1beta1" @@ -35,7 +36,7 @@ var runtimes = map[string]halkyonRuntime{ }, "vert.x": { name: "vert.x", - versions: []string{"3.8.4", "3.7.1"}, + versions: <-getVertXVersions(), generator: `https://start.vertx.io/starter.zip?vertxVersion={{.RV}}&groupId={{.G}}&artifactId={{.A}}&packageName={{.P}}`, }, "thorntail": { @@ -252,6 +253,38 @@ func (o *createOptions) getChildDirNames() []string { return childDirs } +func getVertXVersions() chan []string { + versions := make(chan []string) + go func() { + resp := io.HttpGet("https://start.vertx.io", "metadata", nil) + type version struct { + Number string + Exclusions []string + } + + var objMap map[string]*json.RawMessage + err := json.Unmarshal(resp, &objMap) + if err != nil { + versions <- []string{"couldn't retrieve vert.x metadata: " + err.Error()} + } + + var versionObjs []version + err = json.Unmarshal(*objMap["versions"], &versionObjs) + if err != nil { + versions <- []string{"couldn't retrieve vert.x metadata: " + err.Error()} + } + + vers := make([]string, 0, len(versionObjs)) + for _, v := range versionObjs { + vers = append(vers, v.Number) + } + + versions <- vers + }() + + return versions +} + func getRuntimeNames() []string { result := make([]string, 0, len(runtimes)) for k := range runtimes {