Skip to content

Commit

Permalink
Added condition to skip duplicate subcommands when adding a new comma…
Browse files Browse the repository at this point in the history
…nd with subcommands
  • Loading branch information
kelvinmwinuka committed Apr 29, 2024
1 parent 1d56e98 commit dcb88ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion echovault/api_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (server *EchoVault) RewriteAOF() (string, error) {

// TODO: Write godoc comment for AddCommand method
func (server *EchoVault) AddCommand(command CommandOptions) error {
// Check if commands already exists
// Check if command already exists
for _, c := range server.commands {
if strings.EqualFold(c.Command, command.Command) {
return fmt.Errorf("command %s already exists", command.Command)
Expand Down Expand Up @@ -203,6 +203,12 @@ func (server *EchoVault) AddCommand(command CommandOptions) error {
}

for i, sc := range command.SubCommand {
// Skip the subcommand if it already exists in newCommand
if slices.ContainsFunc(newCommand.SubCommands, func(subcommand internal.SubCommand) bool {
return strings.EqualFold(subcommand.Command, sc.Command)
}) {
continue
}
newCommand.SubCommands[i] = internal.SubCommand{
Command: sc.Command,
Module: strings.ToLower(command.Module),
Expand Down

0 comments on commit dcb88ff

Please sign in to comment.