Skip to content

Commit 1d3d2d6

Browse files
committed
feat(kafka list): add search flag
Search flag has been added to kafka list to filter by text. fixes #181
1 parent 421b165 commit 1d3d2d6

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

cmd/rhoas/pkged.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/commands/rhoas_kafka_list.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rhoas kafka list [flags]
2323
--limit int The maximum number of Kafka instances to be returned (default 100)
2424
-o, --output string Format in which to display the Kafka instances. Choose from: "json", "yml", "yaml"
2525
--page int Display the Kafka instances from the specified page number.
26+
--search string Text search to filter the Kafka instances
2627
....
2728

2829
=== Options inherited from parent commands

locales/cmd/kafka/list/active.en.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ one = 'Display the Kafka instances from the specified page number.'
4040
description = 'Description for the --limit flag'
4141
one = 'The maximum number of Kafka instances to be returned'
4242

43+
[kafka.list.flag.search]
44+
description = 'Description for the --search flag'
45+
one = 'Text search to filter the Kafka instances'
46+
4347
[kafka.list.log.info.noKafkaInstances]
4448
description = 'Info message when no Kafkas were found'
4549
one = 'No Kafka instances were found.'

pkg/cmd/kafka/list/list.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package list
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"os"
78
"strconv"
89

@@ -37,6 +38,7 @@ type options struct {
3738
outputFormat string
3839
page int
3940
limit int
41+
search string
4042

4143
Config config.IConfig
4244
Connection func() (connection.Connection, error)
@@ -48,6 +50,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
4850
opts := &options{
4951
page: 0,
5052
limit: 100,
53+
search: "",
5154
Config: f.Config,
5255
Connection: f.Connection,
5356
Logger: f.Logger,
@@ -75,6 +78,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
7578
}))
7679
cmd.Flags().IntVarP(&opts.page, "page", "", 0, localizer.MustLocalizeFromID("kafka.list.flag.page"))
7780
cmd.Flags().IntVarP(&opts.limit, "limit", "", 100, localizer.MustLocalizeFromID("kafka.list.flag.limit"))
81+
cmd.Flags().StringVarP(&opts.search, "search", "", "", localizer.MustLocalizeFromID("kafka.list.flag.search"))
7882

7983
return cmd
8084
}
@@ -95,6 +99,7 @@ func runList(opts *options) error {
9599
a := api.Kafka().ListKafkas(context.Background())
96100
a = a.Page(strconv.Itoa(opts.page))
97101
a = a.Size(strconv.Itoa(opts.limit))
102+
a = a.Search(buildQuery(opts.search))
98103
response, _, apiErr := a.Execute()
99104

100105
if apiErr.Error() != "" {
@@ -140,3 +145,18 @@ func mapResponseItemsToRows(kafkas []kasclient.KafkaRequest) []kafkaRow {
140145

141146
return rows
142147
}
148+
149+
func buildQuery(search string) string {
150+
151+
var queryString string
152+
153+
if search != "" {
154+
queryString = fmt.Sprintf(
155+
"name like %%%[1]v%% or owner like %%%[1]v%% or cloud_provider like %%%[1]v%% or region like %%%[1]v%% or status like %%%[1]v%%",
156+
search,
157+
)
158+
}
159+
160+
return queryString
161+
162+
}

0 commit comments

Comments
 (0)