MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cliIntegrateHelp

Function cliIntegrateHelp

app/redis-6.2.6/src/redis-cli.c:555–608  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

553 * entries with additional entries obtained using the COMMAND command
554 * available in recent versions of Redis. */
555static void cliIntegrateHelp(void) {
556 if (cliConnect(CC_QUIET) == REDIS_ERR) return;
557
558 redisReply *reply = redisCommand(context, "COMMAND");
559 if(reply == NULL || reply->type != REDIS_REPLY_ARRAY) return;
560
561 /* Scan the array reported by COMMAND and fill only the entries that
562 * don't already match what we have. */
563 for (size_t j = 0; j < reply->elements; j++) {
564 redisReply *entry = reply->element[j];
565 if (entry->type != REDIS_REPLY_ARRAY || entry->elements < 4 ||
566 entry->element[0]->type != REDIS_REPLY_STRING ||
567 entry->element[1]->type != REDIS_REPLY_INTEGER ||
568 entry->element[3]->type != REDIS_REPLY_INTEGER) return;
569 char *cmdname = entry->element[0]->str;
570 int i;
571
572 for (i = 0; i < helpEntriesLen; i++) {
573 helpEntry *he = helpEntries+i;
574 if (!strcasecmp(he->argv[0],cmdname))
575 break;
576 }
577 if (i != helpEntriesLen) continue;
578
579 helpEntriesLen++;
580 helpEntries = zrealloc(helpEntries,sizeof(helpEntry)*helpEntriesLen);
581 helpEntry *new = helpEntries+(helpEntriesLen-1);
582
583 new->argc = 1;
584 new->argv = zmalloc(sizeof(sds));
585 new->argv[0] = sdsnew(cmdname);
586 new->full = new->argv[0];
587 new->type = CLI_HELP_COMMAND;
588 sdstoupper(new->argv[0]);
589
590 struct commandHelp *ch = zmalloc(sizeof(*ch));
591 ch->name = new->argv[0];
592 ch->params = sdsempty();
593 int args = llabs(entry->element[1]->integer);
594 args--; /* Remove the command name itself. */
595 if (entry->element[3]->integer == 1) {
596 ch->params = sdscat(ch->params,"key ");
597 args--;
598 }
599 while(args-- > 0) ch->params = sdscat(ch->params,"arg ");
600 if (entry->element[1]->integer < 0)
601 ch->params = sdscat(ch->params,"...options...");
602 ch->summary = "Help not available";
603 ch->group = 0;
604 ch->since = "not known";
605 new->org = ch;
606 }
607 freeReplyObject(reply);
608}
609
610/* Output command help to stdout. */
611static void cliOutputCommandHelp(struct commandHelp *help, int group) {

Callers 1

replFunction · 0.85

Calls 10

cliConnectFunction · 0.85
strcasecmpFunction · 0.85
zreallocFunction · 0.85
zmallocFunction · 0.85
sdsnewFunction · 0.85
sdstoupperFunction · 0.85
sdsemptyFunction · 0.85
sdscatFunction · 0.85
freeReplyObjectFunction · 0.85
redisCommandClass · 0.70

Tested by

no test coverage detected