Skip to content

Commit

Permalink
topic list: fixup
Browse files Browse the repository at this point in the history
Unfortunately, when we call into the metadata command, we no longer have
persistent flags installed, meaning -X would not work.

Switching to exporting PrintTopics from the metadata command and then
issuing a metadata request directly fixes things.
  • Loading branch information
twmb committed Sep 4, 2021
1 parent 9aaf284 commit 1af92fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions commands/admin/topic/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ func topicListCommand(cl *client.Client) *cobra.Command {
Short: "List all topics",
Long: "List all topics (alias for metadata -t)",
Run: func(_ *cobra.Command, _ []string) {
args := []string{"-t"}
if detailed {
args = append(args, "-d")
}
cmd := metadata.Command(cl)
cmd.SetArgs(args)
cmd.Execute()
req := kmsg.NewPtrMetadataRequest()
resp, err := req.RequestWith(context.Background(), cl.Client())
out.MaybeDie(err, "unable to list topics: %v", err)
metadata.PrintTopics(resp.Version, resp.Topics, false, detailed)
},
}
cmd.Flags().BoolVarP(&detailed, "detailed", "d", false, "include detailed information about all topic partitions")
Expand Down
4 changes: 2 additions & 2 deletions commands/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ If the brokers section is printed, the controller broker is marked with *.
if includeHeader {
fmt.Printf("TOPICS\n======\n")
}
printTopics(resp.Version, resp.Topics, pinternal, detailed)
PrintTopics(resp.Version, resp.Topics, pinternal, detailed)
}
},
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func printBrokers(controllerID int32, brokers []kmsg.MetadataResponseBroker) {
}
}

func printTopics(version int16, topics []kmsg.MetadataResponseTopic, pinternal, detailed bool) {
func PrintTopics(version int16, topics []kmsg.MetadataResponseTopic, pinternal, detailed bool) {
sort.Slice(topics, func(i, j int) bool {
l := topics[i].Topic
r := topics[j].Topic
Expand Down

0 comments on commit 1af92fc

Please sign in to comment.