Skip to content

Commit

Permalink
move confirm to util package
Browse files Browse the repository at this point in the history
  • Loading branch information
petedannemann committed Nov 16, 2023
1 parent 0cd4dcf commit 41981eb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/topicctl/subcmd/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/segmentio/kafka-go"
"github.com/segmentio/topicctl/pkg/apply"
"github.com/segmentio/topicctl/pkg/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -104,7 +104,7 @@ func runTestReader(ctx context.Context) error {
testerConfig.readConsumer,
)

ok, _ := apply.Confirm("OK to continue?", false)
ok, _ := util.Confirm("OK to continue?", false)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func runTestWriter(ctx context.Context) error {
testerConfig.writeRate,
)

ok, _ := apply.Confirm("OK to continue?", false)
ok, _ := util.Confirm("OK to continue?", false)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (t *TopicApplier) applyNewTopic(ctx context.Context) error {
FormatNewTopicConfig(newTopicConfig),
)

ok, _ := Confirm("OK to continue?", t.config.SkipConfirm)
ok, _ := util.Confirm("OK to continue?", t.config.SkipConfirm)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (t *TopicApplier) checkExistingState(
if t.config.DryRun {
log.Infof("Skipping update because dryRun is set to true")
} else {
ok, err := Confirm("OK to remove these?", t.config.SkipConfirm)
ok, err := util.Confirm("OK to remove these?", t.config.SkipConfirm)
if err != nil {
return err
} else if !ok {
Expand Down Expand Up @@ -326,7 +326,7 @@ func (t *TopicApplier) checkExistingState(
if t.config.DryRun {
log.Infof("Skipping update because dryRun is set to true")
} else {
ok, err := Confirm("OK to remove broker throttles?", t.config.SkipConfirm)
ok, err := util.Confirm("OK to remove broker throttles?", t.config.SkipConfirm)
if err != nil {
return err
} else if !ok {
Expand Down Expand Up @@ -413,7 +413,7 @@ func (t *TopicApplier) updateSettings(
return nil
}

ok, _ := Confirm(
ok, _ := util.Confirm(
"OK to update to the new values in the topic config?",
t.config.SkipConfirm,
)
Expand Down Expand Up @@ -576,7 +576,7 @@ func (t *TopicApplier) updatePartitionsHelper(
return nil
}

ok, _ := Confirm("OK to apply?", t.config.SkipConfirm)
ok, _ := util.Confirm("OK to apply?", t.config.SkipConfirm)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down Expand Up @@ -678,7 +678,7 @@ func (t *TopicApplier) updatePlacement(
desiredPlacement,
)

ok, _ := Confirm(
ok, _ := util.Confirm(
fmt.Sprintf("OK to apply %s despite having unbalanced leaders?", desiredPlacement),
t.config.SkipConfirm || t.config.DryRun,
)
Expand Down Expand Up @@ -841,7 +841,7 @@ func (t *TopicApplier) updatePlacementRunner(
log.Warnf("Autocontinue flag detected, user will not be prompted each round")
}

ok, _ := Confirm("OK to apply?", t.config.SkipConfirm)
ok, _ := util.Confirm("OK to apply?", t.config.SkipConfirm)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down Expand Up @@ -917,7 +917,7 @@ func (t *TopicApplier) updatePlacementRunner(
if t.config.AutoContinueRebalance {
log.Infof("Autocontinuing to next round")
} else {
ok, _ := Confirm("OK to continue?", t.config.SkipConfirm)
ok, _ := util.Confirm("OK to continue?", t.config.SkipConfirm)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down Expand Up @@ -1249,7 +1249,7 @@ func (t *TopicApplier) updateLeaders(
batchSize = len(wrongLeaders)
}

ok, _ := Confirm(
ok, _ := util.Confirm(
fmt.Sprintf(
"OK to run leader elections (in batches of %d partitions each) ?",
batchSize,
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func TestLoadTopicsFile(t *testing.T) {
assert.Equal(t, "topic-test2", topicConfigs[1].Meta.Name)
}

// TODO: write this test
func TestLoadACLsFile(t *testing.T) {
aclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test.yaml")
require.NoError(t, err)
Expand Down Expand Up @@ -159,7 +158,6 @@ func TestLoadACLsFile(t *testing.T) {

invalidAclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test-invalid.yaml")
assert.Equal(t, 0, len(invalidAclConfigs))
// TODO: improve this error checking and make sure the error is informative enough
require.Error(t, err)

multiAclConfigs, err := LoadACLsFile("testdata/test-cluster/acls/acl-test-multi.yaml")
Expand Down
5 changes: 2 additions & 3 deletions pkg/create/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/segmentio/kafka-go"
"github.com/segmentio/topicctl/pkg/admin"
"github.com/segmentio/topicctl/pkg/apply"
"github.com/segmentio/topicctl/pkg/config"
"github.com/segmentio/topicctl/pkg/util"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -105,8 +105,7 @@ func (a *ACLCreator) Create(ctx context.Context) error {
formatNewACLsConfig(newACLs),
)

// TODO: move confirm away from apply package
ok, _ := apply.Confirm("OK to continue?", a.config.SkipConfirm)
ok, _ := util.Confirm("OK to continue?", a.config.SkipConfirm)
if !ok {
return errors.New("Stopping because of user response")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apply/confirm.go → pkg/util/confirm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apply
package util

import (
"fmt"
Expand Down

0 comments on commit 41981eb

Please sign in to comment.