From 76ad23d012f194efa1acc0f8356d945b07681851 Mon Sep 17 00:00:00 2001 From: Itamar Haber Date: Thu, 7 Jun 2018 18:34:58 +0300 Subject: [PATCH] Adds MODULE HELP and implements addReplySubSyntaxError --- src/module.c | 13 +++++++++++-- src/networking.c | 12 ++++++++++++ src/server.h | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index cb03ad2cd..e4d6e2cf2 100644 --- a/src/module.c +++ b/src/module.c @@ -4499,7 +4499,15 @@ int moduleUnload(sds name) { * MODULE LOAD [args...] */ void moduleCommand(client *c) { char *subcmd = c->argv[1]->ptr; - + if (c->argc == 2 && !strcasecmp(subcmd,"help")) { + const char *help[] = { +"list -- Return a list of loaded modules.", +"load [arg ...] -- Load a module library from .", +"unload -- Unload a module.", +NULL + }; + addReplyHelp(c, help); + } else if (!strcasecmp(subcmd,"load") && c->argc >= 3) { robj **argv = NULL; int argc = 0; @@ -4548,7 +4556,8 @@ void moduleCommand(client *c) { } dictReleaseIterator(di); } else { - addReply(c,shared.syntaxerr); + addReplySubSyntaxError(c); + return; } } diff --git a/src/networking.c b/src/networking.c index 00558974e..ac28ba2b8 100644 --- a/src/networking.c +++ b/src/networking.c @@ -560,6 +560,18 @@ void addReplyHelp(client *c, const char **help) { setDeferredMultiBulkLength(c,blenp,blen); } +/* Add a suggestive error reply. + * This function is typically invoked by from commands that support + * subcommands in response to an unknown subcommand or argument error. */ +void addReplySubSyntaxError(client *c) { + sds cmd = sdsnew((char*) c->argv[0]->ptr); + sdstoupper(cmd); + addReplyErrorFormat(c, + "Unknown subcommand or wrong number of arguments for '%s'. Try %s HELP.", + c->argv[1]->ptr,cmd); + sdsfree(cmd); +} + /* Copy 'src' client output buffers into 'dst' client output buffers. * The function takes care of freeing the old output buffers of the * destination client. */ diff --git a/src/server.h b/src/server.h index c34cdcfbf..26aee8932 100644 --- a/src/server.h +++ b/src/server.h @@ -1410,6 +1410,7 @@ void addReplyHumanLongDouble(client *c, long double d); void addReplyLongLong(client *c, long long ll); void addReplyMultiBulkLen(client *c, long length); void addReplyHelp(client *c, const char **help); +void addReplySubSyntaxError(client *c); void copyClientOutputBuffer(client *dst, client *src); size_t sdsZmallocSize(sds s); size_t getStringObjectSdsUsedMemory(robj *o);