From 9b2a9054079753e4ff4f4574c615d47b6f6af7ae Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 12:43:20 +0530 Subject: [PATCH 01/10] feat: add support and tests for Command list command --- command.go | 10 ++++++++ commands.go | 19 ++++++++++++++ commands_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/command.go b/command.go index b62d50ddb..1dc4ec8c1 100644 --- a/command.go +++ b/command.go @@ -3992,3 +3992,13 @@ func (cmd *FunctionListCmd) readFunctions(rd *proto.Reader) ([]Function, error) } return functions, nil } + +type FilterBy struct { + Module string + AclCat string + Pattern string +} + +type CommandListOptions struct { + FilterBy *FilterBy +} diff --git a/commands.go b/commands.go index ac93f39c9..c162c6561 100644 --- a/commands.go +++ b/commands.go @@ -124,6 +124,7 @@ type Cmdable interface { TxPipeline() Pipeliner Command(ctx context.Context) *CommandsInfoCmd + CommandList(ctx context.Context, opts *CommandListOptions) *StringSliceCmd ClientGetName(ctx context.Context) *StringCmd Echo(ctx context.Context, message interface{}) *StringCmd Ping(ctx context.Context) *StatusCmd @@ -537,6 +538,24 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { return cmd } +func (c cmdable) CommandList(ctx context.Context, opts *CommandListOptions) *StringSliceCmd { + args := []interface{}{"COMMAND", "LIST"} + if opts != nil && opts.FilterBy != nil { + filter := opts.FilterBy + if filter.Module != "" { + args = append(args, "FILTERBY", "MODULE", filter.Module) + } else if filter.AclCat != "" { + args = append(args, "FILTERBY", "ACLCAT", filter.AclCat) + } else if filter.Pattern != "" { + args = append(args, "FILTERBY", "PATTERN", filter.Pattern) + } + } + cmd := NewStringSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + + // ClientGetName returns the name of the connection. func (c cmdable) ClientGetName(ctx context.Context) *StringCmd { cmd := NewStringCmd(ctx, "client", "getname") diff --git a/commands_test.go b/commands_test.go index f806dc8f5..cedae2348 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6277,6 +6277,71 @@ var _ = Describe("Commands", func() { Expect(err).To(Equal(redis.Nil)) }) + It("should return all command names", func() { + cmdList := client.CommandList(ctx, nil) + Expect(cmdList.Err()).NotTo(HaveOccurred()) + cmdNames := cmdList.Val() + + // Assert that the returned list is not empty + Expect(cmdNames).NotTo(BeEmpty()) + + // Assert that some expected commands are present in the list + Expect(cmdNames).To(ContainElement("GET")) + Expect(cmdNames).To(ContainElement("SET")) + Expect(cmdNames).To(ContainElement("HSET")) + }) + + It("should filter commands by module", func() { + opts := &redis.CommandListOptions{ + FilterBy: &redis.FilterBy{ + Module: "redisearch", + }, + } + cmdList := client.CommandList(ctx, opts) + Expect(cmdList.Err()).NotTo(HaveOccurred()) + cmdNames := cmdList.Val() + + // Assert that the returned list only contains commands from the Redisearch module + Expect(cmdNames).To(ContainElement("FT.CREATE")) + Expect(cmdNames).To(ContainElement("FT.DROPINDEX")) + Expect(cmdNames).NotTo(ContainElement("GET")) + Expect(cmdNames).NotTo(ContainElement("SET")) + }) + + It("should filter commands by ACL category", func() { + opts := &redis.CommandListOptions{ + FilterBy: &redis.FilterBy{ + AclCat: "@sortedset", + }, + } + cmdList := client.CommandList(ctx, opts) + Expect(cmdList.Err()).NotTo(HaveOccurred()) + cmdNames := cmdList.Val() + + // Assert that the returned list only contains commands from the sorted set ACL category + Expect(cmdNames).To(ContainElement("ZADD")) + Expect(cmdNames).To(ContainElement("ZREM")) + Expect(cmdNames).NotTo(ContainElement("GET")) + Expect(cmdNames).NotTo(ContainElement("SET")) + }) + + It("should filter commands by pattern", func() { + opts := &redis.CommandListOptions{ + FilterBy: &redis.FilterBy{ + Pattern: "*GET*", + }, + } + cmdList := client.CommandList(ctx, opts) + Expect(cmdList.Err()).NotTo(HaveOccurred()) + cmdNames := cmdList.Val() + + // Assert that the returned list only contains commands that match the given pattern + Expect(cmdNames).To(ContainElement("GET")) + Expect(cmdNames).To(ContainElement("GETBIT")) + Expect(cmdNames).To(ContainElement("GETRANGE")) + Expect(cmdNames).NotTo(ContainElement("SET")) + }) + It("Dump and restores all libraries", func() { err := client.FunctionLoad(ctx, lib1Code).Err() Expect(err).NotTo(HaveOccurred()) From 16b7a2f7f26986f3f3d4aa48197b662bd01d1186 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 12:57:57 +0530 Subject: [PATCH 02/10] fix: tests --- commands_test.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/commands_test.go b/commands_test.go index cedae2348..e92b2a6d8 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6281,14 +6281,13 @@ var _ = Describe("Commands", func() { cmdList := client.CommandList(ctx, nil) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() - - // Assert that the returned list is not empty + Expect(cmdNames).NotTo(BeEmpty()) // Assert that some expected commands are present in the list - Expect(cmdNames).To(ContainElement("GET")) - Expect(cmdNames).To(ContainElement("SET")) - Expect(cmdNames).To(ContainElement("HSET")) + Expect(cmdNames).To(ContainElement("get")) + Expect(cmdNames).To(ContainElement("set")) + Expect(cmdNames).To(ContainElement("hset")) }) It("should filter commands by module", func() { @@ -6300,12 +6299,11 @@ var _ = Describe("Commands", func() { cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() - - // Assert that the returned list only contains commands from the Redisearch module - Expect(cmdNames).To(ContainElement("FT.CREATE")) - Expect(cmdNames).To(ContainElement("FT.DROPINDEX")) - Expect(cmdNames).NotTo(ContainElement("GET")) - Expect(cmdNames).NotTo(ContainElement("SET")) + + Expect(cmdNames).To(ContainElement("ft.create")) + Expect(cmdNames).To(ContainElement("ft.dropindex")) + Expect(cmdNames).NotTo(ContainElement("get")) + Expect(cmdNames).NotTo(ContainElement("set")) }) It("should filter commands by ACL category", func() { @@ -6319,10 +6317,10 @@ var _ = Describe("Commands", func() { cmdNames := cmdList.Val() // Assert that the returned list only contains commands from the sorted set ACL category - Expect(cmdNames).To(ContainElement("ZADD")) - Expect(cmdNames).To(ContainElement("ZREM")) - Expect(cmdNames).NotTo(ContainElement("GET")) - Expect(cmdNames).NotTo(ContainElement("SET")) + Expect(cmdNames).To(ContainElement("zadd")) + Expect(cmdNames).To(ContainElement("zrem")) + Expect(cmdNames).NotTo(ContainElement("get")) + Expect(cmdNames).NotTo(ContainElement("set")) }) It("should filter commands by pattern", func() { @@ -6336,10 +6334,10 @@ var _ = Describe("Commands", func() { cmdNames := cmdList.Val() // Assert that the returned list only contains commands that match the given pattern - Expect(cmdNames).To(ContainElement("GET")) - Expect(cmdNames).To(ContainElement("GETBIT")) - Expect(cmdNames).To(ContainElement("GETRANGE")) - Expect(cmdNames).NotTo(ContainElement("SET")) + Expect(cmdNames).To(ContainElement("get")) + Expect(cmdNames).To(ContainElement("getbit")) + Expect(cmdNames).To(ContainElement("getrange")) + Expect(cmdNames).NotTo(ContainElement("set")) }) It("Dump and restores all libraries", func() { From 73068a909d804d3e5cf57abe4b76433ffee281e8 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 13:15:38 +0530 Subject: [PATCH 03/10] fix: tests update --- commands.go | 8 ++++---- commands_test.go | 22 +++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/commands.go b/commands.go index c162c6561..103779579 100644 --- a/commands.go +++ b/commands.go @@ -539,15 +539,15 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { } func (c cmdable) CommandList(ctx context.Context, opts *CommandListOptions) *StringSliceCmd { - args := []interface{}{"COMMAND", "LIST"} + args := []interface{}{"command", "list"} if opts != nil && opts.FilterBy != nil { filter := opts.FilterBy if filter.Module != "" { - args = append(args, "FILTERBY", "MODULE", filter.Module) + args = append(args, "filterby", "module", filter.Module) } else if filter.AclCat != "" { - args = append(args, "FILTERBY", "ACLCAT", filter.AclCat) + args = append(args, "filterby", "aclcat", filter.AclCat) } else if filter.Pattern != "" { - args = append(args, "FILTERBY", "PATTERN", filter.Pattern) + args = append(args, "filterby", "pattern", filter.Pattern) } } cmd := NewStringSliceCmd(ctx, args...) diff --git a/commands_test.go b/commands_test.go index e92b2a6d8..4b9cdf356 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6293,36 +6293,28 @@ var _ = Describe("Commands", func() { It("should filter commands by module", func() { opts := &redis.CommandListOptions{ FilterBy: &redis.FilterBy{ - Module: "redisearch", + Module: "JSON", }, } cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) - cmdNames := cmdList.Val() - - Expect(cmdNames).To(ContainElement("ft.create")) - Expect(cmdNames).To(ContainElement("ft.dropindex")) - Expect(cmdNames).NotTo(ContainElement("get")) - Expect(cmdNames).NotTo(ContainElement("set")) + Expect(cmdList.Val()).To(HaveLen(0)) }) It("should filter commands by ACL category", func() { opts := &redis.CommandListOptions{ FilterBy: &redis.FilterBy{ - AclCat: "@sortedset", + AclCat: "admin", }, } cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() - - // Assert that the returned list only contains commands from the sorted set ACL category - Expect(cmdNames).To(ContainElement("zadd")) - Expect(cmdNames).To(ContainElement("zrem")) - Expect(cmdNames).NotTo(ContainElement("get")) - Expect(cmdNames).NotTo(ContainElement("set")) + + // Assert that the returned list only contains commands from the admin ACL category + Expect(len(cmdNames)).To(BeNumerically(">", 10)) }) - + It("should filter commands by pattern", func() { opts := &redis.CommandListOptions{ FilterBy: &redis.FilterBy{ From 4842f315b5ffa591b1af15d1fea06d699bf13df6 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 14:11:32 +0530 Subject: [PATCH 04/10] feat: refactor using pointer for filterby --- command.go | 5 +---- commands.go | 19 +++++++++---------- commands_test.go | 16 ++++++---------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/command.go b/command.go index 1dc4ec8c1..f537594bd 100644 --- a/command.go +++ b/command.go @@ -3995,10 +3995,7 @@ func (cmd *FunctionListCmd) readFunctions(rd *proto.Reader) ([]Function, error) type FilterBy struct { Module string - AclCat string + ACLCat string Pattern string } -type CommandListOptions struct { - FilterBy *FilterBy -} diff --git a/commands.go b/commands.go index 103779579..433e36056 100644 --- a/commands.go +++ b/commands.go @@ -124,7 +124,7 @@ type Cmdable interface { TxPipeline() Pipeliner Command(ctx context.Context) *CommandsInfoCmd - CommandList(ctx context.Context, opts *CommandListOptions) *StringSliceCmd + CommandList(ctx context.Context, opts *FilterBy) *StringSliceCmd ClientGetName(ctx context.Context) *StringCmd Echo(ctx context.Context, message interface{}) *StringCmd Ping(ctx context.Context) *StatusCmd @@ -538,16 +538,15 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { return cmd } -func (c cmdable) CommandList(ctx context.Context, opts *CommandListOptions) *StringSliceCmd { +func (c cmdable) CommandList(ctx context.Context, opts *FilterBy) *StringSliceCmd { args := []interface{}{"command", "list"} - if opts != nil && opts.FilterBy != nil { - filter := opts.FilterBy - if filter.Module != "" { - args = append(args, "filterby", "module", filter.Module) - } else if filter.AclCat != "" { - args = append(args, "filterby", "aclcat", filter.AclCat) - } else if filter.Pattern != "" { - args = append(args, "filterby", "pattern", filter.Pattern) + if opts != nil { + if opts.Module != "" { + args = append(args, "filterby", "module", opts.Module) + } else if opts.ACLCat != "" { + args = append(args, "filterby", "aclcat", opts.ACLCat) + } else if opts.Pattern != "" { + args = append(args, "filterby", "pattern", opts.Pattern) } } cmd := NewStringSliceCmd(ctx, args...) diff --git a/commands_test.go b/commands_test.go index 4b9cdf356..2c3faee71 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6291,10 +6291,8 @@ var _ = Describe("Commands", func() { }) It("should filter commands by module", func() { - opts := &redis.CommandListOptions{ - FilterBy: &redis.FilterBy{ + opts := &redis.FilterBy{ Module: "JSON", - }, } cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) @@ -6302,11 +6300,11 @@ var _ = Describe("Commands", func() { }) It("should filter commands by ACL category", func() { - opts := &redis.CommandListOptions{ - FilterBy: &redis.FilterBy{ - AclCat: "admin", - }, + + opts := &redis.FilterBy{ + ACLCat: "admin", } + cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() @@ -6316,10 +6314,8 @@ var _ = Describe("Commands", func() { }) It("should filter commands by pattern", func() { - opts := &redis.CommandListOptions{ - FilterBy: &redis.FilterBy{ + opts := &redis.FilterBy{ Pattern: "*GET*", - }, } cmdList := client.CommandList(ctx, opts) Expect(cmdList.Err()).NotTo(HaveOccurred()) From 20c80f8420d2c504f51a8026b5787dce8c0dc026 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 14:24:05 +0530 Subject: [PATCH 05/10] feat: renaming opts -> filter --- commands.go | 18 +++++++++--------- commands_test.go | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/commands.go b/commands.go index 433e36056..20031ca30 100644 --- a/commands.go +++ b/commands.go @@ -124,7 +124,7 @@ type Cmdable interface { TxPipeline() Pipeliner Command(ctx context.Context) *CommandsInfoCmd - CommandList(ctx context.Context, opts *FilterBy) *StringSliceCmd + CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd ClientGetName(ctx context.Context) *StringCmd Echo(ctx context.Context, message interface{}) *StringCmd Ping(ctx context.Context) *StatusCmd @@ -538,15 +538,15 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { return cmd } -func (c cmdable) CommandList(ctx context.Context, opts *FilterBy) *StringSliceCmd { +func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { args := []interface{}{"command", "list"} - if opts != nil { - if opts.Module != "" { - args = append(args, "filterby", "module", opts.Module) - } else if opts.ACLCat != "" { - args = append(args, "filterby", "aclcat", opts.ACLCat) - } else if opts.Pattern != "" { - args = append(args, "filterby", "pattern", opts.Pattern) + if filter != nil { + if filter.Module != "" { + args = append(args, "filterby", "module", filter.Module) + } else if filter.ACLCat != "" { + args = append(args, "filterby", "aclcat", filter.ACLCat) + } else if filter.Pattern != "" { + args = append(args, "filterby", "pattern", filter.Pattern) } } cmd := NewStringSliceCmd(ctx, args...) diff --git a/commands_test.go b/commands_test.go index 2c3faee71..421064802 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6291,21 +6291,21 @@ var _ = Describe("Commands", func() { }) It("should filter commands by module", func() { - opts := &redis.FilterBy{ + filter := &redis.FilterBy{ Module: "JSON", } - cmdList := client.CommandList(ctx, opts) + cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) Expect(cmdList.Val()).To(HaveLen(0)) }) It("should filter commands by ACL category", func() { - opts := &redis.FilterBy{ + filter := &redis.FilterBy{ ACLCat: "admin", } - cmdList := client.CommandList(ctx, opts) + cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() @@ -6314,10 +6314,10 @@ var _ = Describe("Commands", func() { }) It("should filter commands by pattern", func() { - opts := &redis.FilterBy{ + filter := &redis.FilterBy{ Pattern: "*GET*", } - cmdList := client.CommandList(ctx, opts) + cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() From ae885ec0592d8dc601075471588294a3f3940b2f Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:03:48 +0530 Subject: [PATCH 06/10] format: fix using formatter --- commands_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/commands_test.go b/commands_test.go index 421064802..1ddb6baec 100644 --- a/commands_test.go +++ b/commands_test.go @@ -6283,44 +6283,44 @@ var _ = Describe("Commands", func() { cmdNames := cmdList.Val() Expect(cmdNames).NotTo(BeEmpty()) - + // Assert that some expected commands are present in the list Expect(cmdNames).To(ContainElement("get")) Expect(cmdNames).To(ContainElement("set")) Expect(cmdNames).To(ContainElement("hset")) }) - + It("should filter commands by module", func() { filter := &redis.FilterBy{ - Module: "JSON", + Module: "JSON", } cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) - Expect(cmdList.Val()).To(HaveLen(0)) + Expect(cmdList.Val()).To(HaveLen(0)) }) - + It("should filter commands by ACL category", func() { - - filter := &redis.FilterBy{ - ACLCat: "admin", + + filter := &redis.FilterBy{ + ACLCat: "admin", } cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() - + // Assert that the returned list only contains commands from the admin ACL category Expect(len(cmdNames)).To(BeNumerically(">", 10)) }) - + It("should filter commands by pattern", func() { - filter := &redis.FilterBy{ - Pattern: "*GET*", + filter := &redis.FilterBy{ + Pattern: "*GET*", } cmdList := client.CommandList(ctx, filter) Expect(cmdList.Err()).NotTo(HaveOccurred()) cmdNames := cmdList.Val() - + // Assert that the returned list only contains commands that match the given pattern Expect(cmdNames).To(ContainElement("get")) Expect(cmdNames).To(ContainElement("getbit")) From ed6188357c5c57c8323cbff04a173879bc5296f6 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:07:33 +0530 Subject: [PATCH 07/10] fix: specify memory --- commands.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 20031ca30..fbd580410 100644 --- a/commands.go +++ b/commands.go @@ -539,7 +539,9 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { } func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { - args := []interface{}{"command", "list"} + args := make([]interface{}, 0, 5) + args[0] = "command" + args[1] = "list" if filter != nil { if filter.Module != "" { args = append(args, "filterby", "module", filter.Module) @@ -554,7 +556,6 @@ func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSlice return cmd } - // ClientGetName returns the name of the connection. func (c cmdable) ClientGetName(ctx context.Context) *StringCmd { cmd := NewStringCmd(ctx, "client", "getname") From 62bf9e280813b1503f9d23d52f317738da7b66f1 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:17:51 +0530 Subject: [PATCH 08/10] fix: specifying memory --- commands.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index fbd580410..3b6280cfb 100644 --- a/commands.go +++ b/commands.go @@ -539,16 +539,22 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { } func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { - args := make([]interface{}, 0, 5) + args := make([]interface{}, 5) args[0] = "command" args[1] = "list" if filter != nil { if filter.Module != "" { - args = append(args, "filterby", "module", filter.Module) + args[2] = "filterby" + args[3] = "module" + args[4] = filter.Module } else if filter.ACLCat != "" { - args = append(args, "filterby", "aclcat", filter.ACLCat) + args[2] = "filterby" + args[3] = "aclcat" + args[4] = filter.ACLCat } else if filter.Pattern != "" { - args = append(args, "filterby", "pattern", filter.Pattern) + args[2] = "filterby" + args[3] = "pattern" + args[4] = filter.Pattern } } cmd := NewStringSliceCmd(ctx, args...) From 1c6213a7eb1a92bc09859d140f3e7c23332db7ab Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:24:21 +0530 Subject: [PATCH 09/10] fix: size --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 3b6280cfb..e323e3feb 100644 --- a/commands.go +++ b/commands.go @@ -539,7 +539,7 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { } func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { - args := make([]interface{}, 5) + args := make([]interface{}, 2, 5) args[0] = "command" args[1] = "list" if filter != nil { From ac55af4e2a61e2d5fa1e75dc7220b41e7b7a6ca1 Mon Sep 17 00:00:00 2001 From: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Date: Sun, 19 Mar 2023 15:30:41 +0530 Subject: [PATCH 10/10] fix: size issues --- commands.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/commands.go b/commands.go index e323e3feb..da23db220 100644 --- a/commands.go +++ b/commands.go @@ -539,22 +539,15 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd { } func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { - args := make([]interface{}, 2, 5) - args[0] = "command" - args[1] = "list" + args := make([]interface{}, 0, 5) + args = append(args, "command", "list") if filter != nil { if filter.Module != "" { - args[2] = "filterby" - args[3] = "module" - args[4] = filter.Module + args = append(args, "filterby", "module", filter.Module) } else if filter.ACLCat != "" { - args[2] = "filterby" - args[3] = "aclcat" - args[4] = filter.ACLCat + args = append(args, "filterby", "aclcat", filter.ACLCat) } else if filter.Pattern != "" { - args[2] = "filterby" - args[3] = "pattern" - args[4] = filter.Pattern + args = append(args, "filterby", "pattern", filter.Pattern) } } cmd := NewStringSliceCmd(ctx, args...)