Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Add listTopics
Browse files Browse the repository at this point in the history
  • Loading branch information
Mick Staugaard committed Jun 11, 2020
1 parent e2b2208 commit dd26cb7
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 40 deletions.
34 changes: 34 additions & 0 deletions cmd/listTopics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// listTopicsCmd represents the listTopics command
var listTopicsCmd = &cobra.Command{
Use: "listTopics",
Short: "List all the topics",
Long: `listTopics all the topics. Example:
kafkaCLI listTopics --bootstrap-server kafka:9092
`,
Run: func(cmd *cobra.Command, args []string) {
admin := kafkaAdmin()
topics, err := admin.ListTopics()
if err != nil {
panic(err)
}

for name, _ := range topics {
fmt.Println(name)
}

_ = admin.Close()
},
}

func init() {
rootCmd.AddCommand(listTopicsCmd)
}
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ module github.com/vend/kafkaCLI
go 1.13

require (
github.com/Shopify/sarama v1.24.1
github.com/klauspost/cpuid v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/Shopify/sarama v1.26.4
github.com/klauspost/compress v1.10.8 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
)
Loading

0 comments on commit dd26cb7

Please sign in to comment.