diff --git a/build.go b/build.go index 9281d04..e87a540 100644 --- a/build.go +++ b/build.go @@ -40,14 +40,33 @@ type Artifact struct { // String returns a text serialization of the Artifact func (a Artifact) String() string { + return a.toString(true, " ") +} + +// Print returns a string with a pretty print of the artifact +func (a Artifact) Print() string { + return a.toString(true, "\n") +} + +// PrintSummary returns a string with a pretty print of the artifact +func (a Artifact) PrintSummary() string { + return a.toString(false, "\n") +} + +// Print returns a text serialization of the Artifact +func (a Artifact) toString(details bool, sep string) string { buffer := &bytes.Buffer{} - buffer.WriteString(fmt.Sprintf(" id: %s", a.ID)) - buffer.WriteString(fmt.Sprintf("platform: %s", a.Platform)) + if details { + buffer.WriteString(fmt.Sprintf("id: %s%s", a.ID, sep)) + } + buffer.WriteString(fmt.Sprintf("platform: %s%s", a.Platform, sep)) for dep, version := range a.Dependencies { - buffer.WriteString(fmt.Sprintf(" %s:%q", dep, version)) + buffer.WriteString(fmt.Sprintf("%s:%q%s", dep, version, sep)) + } + buffer.WriteString(fmt.Sprintf("checksum: %s%s", a.Checksum, sep)) + if details { + buffer.WriteString(fmt.Sprintf("url: %s%s", a.URL, sep)) } - buffer.WriteString(fmt.Sprintf(" checksum: %s", a.Checksum)) - buffer.WriteString(fmt.Sprintf(" url: %s", a.URL)) return buffer.String() } diff --git a/cmd/local/local.go b/cmd/local/local.go index a30d9a0..5288590 100644 --- a/cmd/local/local.go +++ b/cmd/local/local.go @@ -2,7 +2,6 @@ package local import ( - "encoding/json" "errors" "fmt" "io" @@ -25,23 +24,32 @@ dependencies. Requires the golang toolchain and git. ` example = ` -# build k6 v0.50.0 with latest version of k6/x/kubernetes -k6build local -k v0.50.0 -d k6/x/kubernetes +# build k6 v0.51.0 with latest version of k6/x/kubernetes +k6build local -k v0.51.0 -d k6/x/kubernetes + +platform: linux/amd64 +k6: v0.51.0 +k6/x/kubernetes: v0.9.0 +checksum: 7f06720503c80153816b4ef9f58571c2fce620e0447fba1bb092188ff87e322d # build k6 v0.51.0 with k6/x/kubernetes v0.8.0 and k6/x/output-kafka v0.7.0 k6build local -k v0.51.0 \ -d k6/x/kubernetes:v0.8.0 \ -d k6/x/output-kafka:v0.7.0 -# build latest version of k6 with a version of k6/x/kubernetes greater than v0.8.0 -k6build local -k v0.50.0 -d 'k6/x/kubernetes:>v0.8.0' +platform: linux/amd64 +k6: v0.51.0 +k6/x/kubernetes: v0.8.0 +k6/x/output-kafka": v0.7.0 +checksum: f4af178bb2e29862c0fc7d481076c9ba4468572903480fe9d6c999fea75f3793 + # build k6 v0.50.0 with latest version of k6/x/kubernetes using a custom catalog k6build local -k v0.50.0 -d k6/x/kubernetes \ - -c /path/to/catalog.json + -c /path/to/catalog.json -q # build k6 v0.50.0 using a custom GOPROXY -k6build local -k v0.50.0 -e GOPROXY=http://localhost:80 +k6build local -k v0.50.0 -e GOPROXY=http://localhost:80 -q ` ) @@ -86,12 +94,7 @@ func New() *cobra.Command { //nolint:funlen } if !quiet { - encoder := json.NewEncoder(os.Stdout) - encoder.SetIndent("", " ") - err = encoder.Encode(artifact) - if err != nil { - return fmt.Errorf("processing object %w", err) - } + fmt.Println(artifact.PrintSummary()) } binaryURL, err := url.Parse(artifact.URL) diff --git a/cmd/remote/remote.go b/cmd/remote/remote.go index f593394..5400e41 100644 --- a/cmd/remote/remote.go +++ b/cmd/remote/remote.go @@ -2,7 +2,6 @@ package remote import ( - "encoding/json" "fmt" "io" "net/http" @@ -29,17 +28,14 @@ k6build remote -s http://localhost:8000 \ -d k6/x/kubernetes:v0.8.0 \ -d k6/x/output-kafka:v0.7.0 -{ - "id": "62d08b13fdef171435e2c6874eaad0bb35f2f9c7", - "url": "http://localhost:8000/cache/62d08b13fdef171435e2c6874eaad0bb35f2f9c7/download", - "dependencies": { - "k6": "v0.51.0", - "k6/x/kubernetes": "v0.9.0", - "k6/x/output-kafka": "v0.7.0" - }, - "platform": "linux/amd64", - "checksum": "f4af178bb2e29862c0fc7d481076c9ba4468572903480fe9d6c999fea75f3793" -} +id: 62d08b13fdef171435e2c6874eaad0bb35f2f9c7 +platform: linux/amd64 +k6: v0.51.0 +k6/x/kubernetes: v0.9.0 +k6/x/output-kafka": v0.7.0 +checksum: f4af178bb2e29862c0fc7d481076c9ba4468572903480fe9d6c999fea75f3793 +url: http://localhost:8000/cache/62d08b13fdef171435e2c6874eaad0bb35f2f9c7/download + # build k6 v0.51 with k6/x/output-kafka v0.7.0 and download as 'build/k6' k6build remote -s http://localhost:8000 @@ -56,7 +52,7 @@ Extensions: ) // New creates new cobra command for build client command. -func New() *cobra.Command { //nolint:funlen +func New() *cobra.Command { var ( config client.BuildServiceClientConfig deps []string @@ -96,12 +92,7 @@ func New() *cobra.Command { //nolint:funlen } if !quiet { - encoder := json.NewEncoder(os.Stdout) - encoder.SetIndent("", " ") - err = encoder.Encode(artifact) - if err != nil { - return fmt.Errorf("processing response %w", err) - } + fmt.Println(artifact.Print()) } if output != "" {