From afda40f5da234f34f60960955f38d6275901f0fd Mon Sep 17 00:00:00 2001 From: Ramakrishna Pattnaik Date: Wed, 7 Jul 2021 22:37:51 +0530 Subject: [PATCH] feat(consumer-group list): add search flag --- docs/commands/rhoas_kafka_consumer-group_list.adoc | 1 + pkg/cmd/kafka/consumergroup/list/list.go | 7 +++++++ .../locales/en/cmd/kafka_consumergroup_list.en.toml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/docs/commands/rhoas_kafka_consumer-group_list.adoc b/docs/commands/rhoas_kafka_consumer-group_list.adoc index 06e0ecc9c..b0efefe48 100644 --- a/docs/commands/rhoas_kafka_consumer-group_list.adoc +++ b/docs/commands/rhoas_kafka_consumer-group_list.adoc @@ -30,6 +30,7 @@ $ rhoas kafka consumer-group list -o json `--limit` _int32_:: The maximum number of consumer groups to be returned (default 1000) `-o`, `--output` _string_:: Format in which to display the consumer groups. Choose from: "json", "yml", "yaml" + `--search` _string_:: Text search to filter consumer groups by ID `--topic` _string_:: Fetch the consumer groups for a specific Kafka topic [discrete] diff --git a/pkg/cmd/kafka/consumergroup/list/list.go b/pkg/cmd/kafka/consumergroup/list/list.go index 12c66e3f2..3d8478d94 100644 --- a/pkg/cmd/kafka/consumergroup/list/list.go +++ b/pkg/cmd/kafka/consumergroup/list/list.go @@ -34,6 +34,7 @@ type Options struct { kafkaID string limit int32 topic string + search string } type consumerGroupRow struct { @@ -81,6 +82,7 @@ func NewListConsumerGroupCommand(f *factory.Factory) *cobra.Command { cmd.Flags().Int32VarP(&opts.limit, "limit", "", 1000, opts.localizer.MustLocalize("kafka.consumerGroup.list.flag.limit")) cmd.Flags().StringVarP(&opts.output, "output", "o", "", opts.localizer.MustLocalize("kafka.consumerGroup.list.flag.output.description")) cmd.Flags().StringVar(&opts.topic, "topic", "", opts.localizer.MustLocalize("kafka.consumerGroup.list.flag.topic.description")) + cmd.Flags().StringVar(&opts.search, "search", "", opts.localizer.MustLocalize("kafka.consumerGroup.list.flag.search")) _ = cmd.RegisterFlagCompletionFunc("topic", func(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { return cmdutil.FilterValidTopicNameArgs(f, toComplete) @@ -91,6 +93,7 @@ func NewListConsumerGroupCommand(f *factory.Factory) *cobra.Command { return cmd } +// nolint:funlen func runList(opts *Options) (err error) { conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth) if err != nil { @@ -114,6 +117,10 @@ func runList(opts *Options) (err error) { if opts.topic != "" { req = req.Topic(opts.topic) } + if opts.search != "" { + req = req.GroupIdFilter(opts.search) + } + consumerGroupData, httpRes, err := req.Execute() if err != nil { if httpRes == nil { diff --git a/pkg/localize/locales/en/cmd/kafka_consumergroup_list.en.toml b/pkg/localize/locales/en/cmd/kafka_consumergroup_list.en.toml index b7a198e2f..6bf329e50 100644 --- a/pkg/localize/locales/en/cmd/kafka_consumergroup_list.en.toml +++ b/pkg/localize/locales/en/cmd/kafka_consumergroup_list.en.toml @@ -21,6 +21,10 @@ $ rhoas kafka consumer-group list -o json description = 'Description for the --limit flag' one = 'The maximum number of consumer groups to be returned' +[kafka.consumerGroup.list.flag.search] +description = 'Description for the --search flag' +one = 'Text search to filter consumer groups by ID' + [kafka.consumerGroup.list.log.info.noConsumerGroups] one = 'Kafka instance "{{.InstanceName}}" has no consumer groups'