Unverified Commit f8e2279e authored by Huang Zhw's avatar Huang Zhw Committed by GitHub
Browse files

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]]
```
parent e21c0599
...@@ -943,7 +943,7 @@ static void completionCallback(const char *buf, linenoiseCompletions *lc) { ...@@ -943,7 +943,7 @@ static void completionCallback(const char *buf, linenoiseCompletions *lc) {
static char *hintsCallback(const char *buf, int *color, int *bold) { static char *hintsCallback(const char *buf, int *color, int *bold) {
if (!pref.hints) return NULL; 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); sds *rawargv, *argv = sdssplitargs(buf,&argc);
int endspace = buflen && isspace(buf[buflen-1]); int endspace = buflen && isspace(buf[buflen-1]);
helpEntry *entry = NULL; helpEntry *entry = NULL;
...@@ -954,6 +954,16 @@ static char *hintsCallback(const char *buf, int *color, int *bold) { ...@@ -954,6 +954,16 @@ static char *hintsCallback(const char *buf, int *color, int *bold) {
return NULL; 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 */ /* Search longest matching prefix command */
for (i = 0; i < helpEntriesLen; i++) { for (i = 0; i < helpEntriesLen; i++) {
if (!(helpEntries[i].type & CLI_HELP_COMMAND)) continue; if (!(helpEntries[i].type & CLI_HELP_COMMAND)) continue;
...@@ -973,7 +983,7 @@ static char *hintsCallback(const char *buf, int *color, int *bold) { ...@@ -973,7 +983,7 @@ static char *hintsCallback(const char *buf, int *color, int *bold) {
} }
sdsfreesplitres(rawargv,rawargc); sdsfreesplitres(rawargv,rawargc);
} }
sdsfreesplitres(argv,argc); sdsfreesplitres(argv - shift,argc + shift);
if (entry) { if (entry) {
*color = 90; *color = 90;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment