diff options
author | Huang Zhw <huang_zhw@126.com> | 2022-09-29 14:49:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 09:49:53 +0300 |
commit | f8e2279e3a32d0fc88c09def807fe8a4b03771b2 (patch) | |
tree | 62213a2e832bc22e7770f5c6f1f03824db69575e /src/redis-cli.c | |
parent | e21c05996752e43c324645dd7508013271d95292 (diff) | |
download | redis-f8e2279e3a32d0fc88c09def807fe8a4b03771b2.tar.gz |
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]]
```
Diffstat (limited to 'src/redis-cli.c')
-rw-r--r-- | src/redis-cli.c | 14 |
1 files 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; |