From f8e2279e3a32d0fc88c09def807fe8a4b03771b2 Mon Sep 17 00:00:00 2001 From: Huang Zhw Date: Thu, 29 Sep 2022 14:49:53 +0800 Subject: [PATCH] Add redis-cli hints to ACL DRYRUN, COMMAND GETKEYS, COMMAND GETKEYSANDFLAGS (#11232) Better redis-cli hints for commands that take other commands as arguments. ``` command getkeysandflags hello [protover [AUTH username password]] acl dryrun user hello [protover [AUTH username password]] ``` --- src/redis-cli.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 40b1194f7..147231540 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -943,7 +943,7 @@ static void completionCallback(const char *buf, linenoiseCompletions *lc) { static char *hintsCallback(const char *buf, int *color, int *bold) { if (!pref.hints) return NULL; - int i, rawargc, argc, buflen = strlen(buf), matchlen = 0; + int i, rawargc, argc, buflen = strlen(buf), matchlen = 0, shift = 0; sds *rawargv, *argv = sdssplitargs(buf,&argc); int endspace = buflen && isspace(buf[buflen-1]); helpEntry *entry = NULL; @@ -954,6 +954,16 @@ static char *hintsCallback(const char *buf, int *color, int *bold) { return NULL; } + if (argc > 3 && (!strcasecmp(argv[0], "acl") && !strcasecmp(argv[1], "dryrun"))) { + shift = 3; + } else if (argc > 2 && (!strcasecmp(argv[0], "command") && + (!strcasecmp(argv[1], "getkeys") || !strcasecmp(argv[1], "getkeysandflags")))) + { + shift = 2; + } + argc -= shift; + argv += shift; + /* Search longest matching prefix command */ for (i = 0; i < helpEntriesLen; i++) { if (!(helpEntries[i].type & CLI_HELP_COMMAND)) continue; @@ -973,7 +983,7 @@ static char *hintsCallback(const char *buf, int *color, int *bold) { } sdsfreesplitres(rawargv,rawargc); } - sdsfreesplitres(argv,argc); + sdsfreesplitres(argv - shift,argc + shift); if (entry) { *color = 90;