Skip to content

Commit

Permalink
improve output
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
  • Loading branch information
pablochacin committed Aug 27, 2024
1 parent 90c14f2 commit 8652ec6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
29 changes: 24 additions & 5 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
29 changes: 16 additions & 13 deletions cmd/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package local

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -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
`
)

Expand Down Expand Up @@ -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)
Expand Down
29 changes: 10 additions & 19 deletions cmd/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package remote

import (
"encoding/json"
"fmt"
"io"
"net/http"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 8652ec6

Please # to comment.