Skip to content

Commit

Permalink
rpk: change exit status for topic command failures
Browse files Browse the repository at this point in the history
  • Loading branch information
r-vasquez committed May 9, 2022
1 parent 54f2f84 commit 2d4fbc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/go/rpk/pkg/cli/cmd/topic/add_partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package topic

import (
"context"
"os"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka"
Expand Down Expand Up @@ -42,13 +43,21 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command {
resps, err := adm.CreatePartitions(context.Background(), num, topics...)
out.MaybeDie(err, "create partitions request failed: %v", err)

var exit1 bool
defer func() {
if exit1 {
os.Exit(1)
}
}()

tw := out.NewTable("topic", "error")
defer tw.Flush()

for _, resp := range resps.Sorted() {
msg := "OK"
if e := resp.Err; e != nil {
msg = e.Error()
exit1 = true
}
tw.Print(resp.Topic, msg)
}
Expand Down
9 changes: 9 additions & 0 deletions src/go/rpk/pkg/cli/cmd/topic/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package topic

import (
"context"
"os"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka"
Expand Down Expand Up @@ -85,13 +86,21 @@ the cleanup.policy=compact config option set.
resp, err := req.RequestWith(context.Background(), cl)
out.MaybeDie(err, "unable to create topics %v: %v", topics, err)

var exit1 bool
defer func() {
if exit1 {
os.Exit(1)
}
}()

tw := out.NewTable("topic", "status")
defer tw.Flush()

for _, topic := range resp.Topics {
msg := "OK"
if err := kerr.ErrorForCode(topic.ErrorCode); err != nil {
msg = err.Error()
exit1 = true
}
tw.Print(topic.Topic, msg)
}
Expand Down

0 comments on commit 2d4fbc1

Please sign in to comment.