Call a command
(ctx *Context)
| 84 | |
| 85 | // Call a command |
| 86 | func Call(ctx *Context) { |
| 87 | ctx.Name = strings.ToLower(ctx.Name) |
| 88 | |
| 89 | if ctx.Name != "auth" && |
| 90 | ctx.Server.RequirePass != "" && |
| 91 | ctx.Client.Authenticated == false { |
| 92 | resp.ReplyError(ctx.Out, ErrNoAuth.Error()) |
| 93 | return |
| 94 | } |
| 95 | // Exec all queued commands if this is an exec command |
| 96 | if ctx.Name == "exec" { |
| 97 | if len(ctx.Args) != 0 { |
| 98 | resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error()) |
| 99 | return |
| 100 | } |
| 101 | // Exec must begin with multi |
| 102 | if !ctx.Client.Multi { |
| 103 | resp.ReplyError(ctx.Out, ErrExec.Error()) |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | Exec(ctx) |
| 108 | feedMonitors(ctx) |
| 109 | return |
| 110 | } |
| 111 | // Discard all queued commands and return |
| 112 | if ctx.Name == "discard" { |
| 113 | if !ctx.Client.Multi { |
| 114 | resp.ReplyError(ctx.Out, ErrDiscard.Error()) |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | Discard(ctx) |
| 119 | feedMonitors(ctx) |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | cmdInfoCommand, ok := commands[ctx.Name] |
| 124 | if !ok { |
| 125 | resp.ReplyError(ctx.Out, ErrUnKnownCommand(ctx.Name).Error()) |
| 126 | return |
| 127 | } |
| 128 | argc := len(ctx.Args) + 1 // include the command name |
| 129 | arity := cmdInfoCommand.Cons.Arity |
| 130 | |
| 131 | if arity > 0 && argc != arity { |
| 132 | resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error()) |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | if arity < 0 && argc < -arity { |
| 137 | resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error()) |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | // We now in a multi block, queue the command and return |
| 142 | if ctx.Client.Multi { |
| 143 | if ctx.Name == "multi" { |