-
Notifications
You must be signed in to change notification settings - Fork 23
feature: list topics command #7
Copy link
Copy link
Closed
Description
It's often useful to be able to list all available topics. kcl could support this with a kcl topic list command:
kcl topic list
Topic Partitions Internal?
topic1 3 false
topic2 3 false
topic3 3 false
It could also include optional internal topic filtering. What do you think?
There's some potential complication with handling Kafka versions < 0.10.0 due to kmsg.MetadataRequest.Topics taking nil or and empty slice to indicate all topics but the gist of the command is something like:
func topicListCommand(cl *client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all topics (Kafka 0.10.0.0+)",
Run: func(_ *cobra.Command, topics []string) {
req := kmsg.NewMetadataRequest()
kresp, err := cl.Client().Request(context.Background(), &req)
out.MaybeDie(err, "unable to list topics: %v", err)
resp := kresp.(*kmsg.MetadataResponse)
if cl.AsJSON() {
out.ExitJSON(resp.Topics)
}
tw := out.BeginTabWrite()
defer tw.Flush()
fmt.Fprintln(tw, "Topic\tPartitions\tInternal?")
for _, topicResp := range resp.Topics {
fmt.Fprintf(tw, "%s\t%d\t%t\n", topicResp.Topic, len(topicResp.Partitions), topicResp.IsInternal)
}
},
}
return cmd
}Happy to submit a PR for implementation if desired 😄
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels