Skip to content

Commit

Permalink
fix: retrieve vert.x versions from generator
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
metacosm committed Nov 23, 2019
1 parent 4603b71 commit d514115
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pkg/hal/cli/component/create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package component

import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"halkyon.io/api/component/v1beta1"
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d514115

Please sign in to comment.