Skip to content

Commit

Permalink
topic/create: add flag for compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
birdayz committed Oct 15, 2018
1 parent e70fffd commit 6b29062
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/kaf/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
partitionsFlag int32
replicasFlag int16
noHeaderFlag bool
compactFlag bool
)

func init() {
Expand All @@ -26,6 +27,7 @@ func init() {

createTopicCmd.Flags().Int32VarP(&partitionsFlag, "partitions", "p", int32(1), "Number of partitions")
createTopicCmd.Flags().Int16VarP(&replicasFlag, "replicas", "r", int16(1), "Number of replicas")
createTopicCmd.Flags().BoolVarP(&compactFlag, "compact", "c", false, "Enable topic compaction")

lsTopicsCmd.Flags().BoolVar(&noHeaderFlag, "no-headers", false, "Hide table headers")
}
Expand Down Expand Up @@ -173,9 +175,13 @@ var createTopicCmd = &cobra.Command{
panic(err)
}

compact := "compact"
err = admin.CreateTopic(args[0], &sarama.TopicDetail{
NumPartitions: partitionsFlag,
ReplicationFactor: replicasFlag,
ConfigEntries: map[string]*string{
"cleanup.policy": &compact,
},
}, false)
if err != nil {
fmt.Printf("Could not create topic %v: %v\n", args[0], err.Error())
Expand Down

0 comments on commit 6b29062

Please sign in to comment.