Skip to content

Commit

Permalink
Add option for supressing artifact output
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Jun 23, 2024
1 parent 911852a commit 6ecf25f
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,65 @@ k6build client connects to a remote build server
`

clientExamples = `
# build latest k6 version
k6build client -s http://localhost:8000
# build and download k6 v0.50.0 to 'build/k6'
k6build client -s http://localhost:8000
-k v0.50.0 -d k6/x/kubernetes \
-o build/k6
k6build client -s http://localhost:8000 -k v0.50.0 -d k6/x/kubernetes
# build k6 v0.51.0 with k6/x/kubernetes v0.8.0 and k6/x/output-kafka v0.7.0
k6build client -s http://localhost:8000 \
-k v0.51.0 \
-k v0.51.0 \
-p linux/amd64
-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"
}
# build k6 v0.51 with k6/x/output-kafka v0.7.0 and download to 'build/k6'
k6build client -s http://localhost:8000
-p linux/amd64
-k v0.51.0 -d k6/x/output-kafka:v0.7.0
-o build/k6 -q
# check binary
build/k6 version
k6 v0.51.0 (go1.22.2, linux/amd64)
Extensions:
github.com/grafana/xk6-output-kafka v0.7.0, xk6-kafka [output]
# build latest version of k6 with a version of k6/x/kubernetes greater than v0.8.0
k6build client -s http://localhost:8000 \
-p linux/amd64 \
-k v0.50.0 -d 'k6/x/kubernetes:>v0.8.0'
{
"id": "18035a12975b262430b55988ffe053098d020034",
"url": "http://localhost:8000/cache/18035a12975b262430b55988ffe053098d020034/download",
"dependencies": {
"k6": "v0.50.0",
"k6/x/kubernetes": "v0.9.0"
},
"platform": "linux/amd64",
"checksum": "255e5d62852af5e4109a0ac6f5818936a91c986919d12d8437e97fb96919847b"
}
`
)

// NewClient creates new cobra command for build client command.
func NewClient() *cobra.Command {
func NewClient() *cobra.Command { //nolint:funlen
var (
config k6build.BuildServiceClientConfig
deps []string
k6 string
output string
platform string
quiet bool
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -79,11 +108,13 @@ func NewClient() *cobra.Command {
return fmt.Errorf("building %w", err)
}

encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
err = encoder.Encode(artifact)
if err != nil {
return fmt.Errorf("processing response %w", err)
if !quiet {
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
err = encoder.Encode(artifact)
if err != nil {
return fmt.Errorf("processing response %w", err)
}
}

if output != "" {
Expand Down Expand Up @@ -120,6 +151,7 @@ func NewClient() *cobra.Command {
cmd.Flags().StringVarP(&platform, "platform", "p", "", "target platform (default GOOS/GOARCH)")
cmd.Flags().StringVarP(&output, "output", "o", "", "path to download the artifact as an executable."+
" If not specified, the artifact is not downloaded.")
cmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "don't print artifact's details")

return cmd
}

0 comments on commit 6ecf25f

Please sign in to comment.