From 2d4fbc1fb1e1dbdf468d0716acc4e7838bb5f106 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Thu, 5 May 2022 17:20:08 -0500 Subject: [PATCH] rpk: change exit status for topic command failures --- src/go/rpk/pkg/cli/cmd/topic/add_partitions.go | 9 +++++++++ src/go/rpk/pkg/cli/cmd/topic/create.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go index 91d8fae6773a..683b9c3d8eab 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go +++ b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go @@ -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" @@ -42,6 +43,13 @@ 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() @@ -49,6 +57,7 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command { msg := "OK" if e := resp.Err; e != nil { msg = e.Error() + exit1 = true } tw.Print(resp.Topic, msg) } diff --git a/src/go/rpk/pkg/cli/cmd/topic/create.go b/src/go/rpk/pkg/cli/cmd/topic/create.go index 67e1890cd2f4..ec42df37daaf 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/create.go +++ b/src/go/rpk/pkg/cli/cmd/topic/create.go @@ -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" @@ -85,6 +86,13 @@ 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() @@ -92,6 +100,7 @@ the cleanup.policy=compact config option set. msg := "OK" if err := kerr.ErrorForCode(topic.ErrorCode); err != nil { msg = err.Error() + exit1 = true } tw.Print(topic.Topic, msg) }