cliInitHelp() setups the helpEntries array with the command and group * names from the help.h file. However the Redis instance we are connecting * to may support more commands, so this function integrates the previous * entries with additional entries obtained using the COMMAND command * available in recent versions of Redis. */
| 360 | * entries with additional entries obtained using the COMMAND command |
| 361 | * available in recent versions of Redis. */ |
| 362 | static void cliIntegrateHelp(void) { |
| 363 | if (cliConnect(CC_QUIET) == REDIS_ERR) return; |
| 364 | |
| 365 | redisReply *reply = redisCommand(context, "COMMAND"); |
| 366 | if(reply == NULL || reply->type != REDIS_REPLY_ARRAY) return; |
| 367 | |
| 368 | /* Scan the array reported by COMMAND and fill only the entries that |
| 369 | * don't already match what we have. */ |
| 370 | for (size_t j = 0; j < reply->elements; j++) { |
| 371 | redisReply *entry = reply->element[j]; |
| 372 | if (entry->type != REDIS_REPLY_ARRAY || entry->elements < 4 || |
| 373 | entry->element[0]->type != REDIS_REPLY_STRING || |
| 374 | entry->element[1]->type != REDIS_REPLY_INTEGER || |
| 375 | entry->element[3]->type != REDIS_REPLY_INTEGER) return; |
| 376 | char *cmdname = entry->element[0]->str; |
| 377 | int i; |
| 378 | |
| 379 | for (i = 0; i < helpEntriesLen; i++) { |
| 380 | helpEntry *he = helpEntries+i; |
| 381 | if (!strcasecmp(he->argv[0],cmdname)) |
| 382 | break; |
| 383 | } |
| 384 | if (i != helpEntriesLen) continue; |
| 385 | |
| 386 | helpEntriesLen++; |
| 387 | helpEntries = zrealloc(helpEntries,sizeof(helpEntry)*helpEntriesLen, MALLOC_LOCAL); |
| 388 | helpEntry *new = helpEntries+(helpEntriesLen-1); |
| 389 | |
| 390 | new->argc = 1; |
| 391 | new->argv = zmalloc(sizeof(sds), MALLOC_LOCAL); |
| 392 | new->argv[0] = sdsnew(cmdname); |
| 393 | new->full = new->argv[0]; |
| 394 | new->type = CLI_HELP_COMMAND; |
| 395 | sdstoupper(new->argv[0]); |
| 396 | |
| 397 | struct commandHelp *ch = zmalloc(sizeof(*ch), MALLOC_LOCAL); |
| 398 | ch->name = new->argv[0]; |
| 399 | ch->params = sdsempty(); |
| 400 | int args = llabs(entry->element[1]->integer); |
| 401 | args--; /* Remove the command name itself. */ |
| 402 | if (entry->element[3]->integer == 1) { |
| 403 | ch->params = sdscat(ch->params,"key "); |
| 404 | args--; |
| 405 | } |
| 406 | while(args-- > 0) ch->params = sdscat(ch->params,"arg "); |
| 407 | if (entry->element[1]->integer < 0) |
| 408 | ch->params = sdscat(ch->params,"...options..."); |
| 409 | ch->summary = "Help not available"; |
| 410 | ch->group = 0; |
| 411 | ch->since = "not known"; |
| 412 | new->org = ch; |
| 413 | } |
| 414 | freeReplyObject(reply); |
| 415 | } |
| 416 | |
| 417 | /* Output command help to stdout. */ |
| 418 | static void cliOutputCommandHelp(struct commandHelp *help, int group) { |
no test coverage detected