MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / cliIntegrateHelp

Function cliIntegrateHelp

src/redis-cli.c:362–415  ·  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

360 * entries with additional entries obtained using the COMMAND command
361 * available in recent versions of Redis. */
362static 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. */
418static void cliOutputCommandHelp(struct commandHelp *help, int group) {

Callers 1

replFunction · 0.85

Calls 9

cliConnectFunction · 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