+#define CLI_HELP_COMMAND 1
+#define CLI_HELP_GROUP 2
+
+typedef struct {
+ int type;
+ int argc;
+ sds *argv;
+ sds full;
+
+ /* Only used for help on commands */
+ struct commandHelp *org;
+} helpEntry;
+
+static helpEntry *helpEntries;
+static int helpEntriesLen;
+
+static sds cliVersion() {
+ sds version;
+ version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION);
+
+ /* Add git commit and working tree status when available */
+ if (strtoll(redisGitSHA1(),NULL,16)) {
+ version = sdscatprintf(version, " (git:%s", redisGitSHA1());
+ if (strtoll(redisGitDirty(),NULL,10))
+ version = sdscatprintf(version, "-dirty");
+ version = sdscat(version, ")");
+ }
+ return version;
+}
+
+static void cliInitHelp() {
+ int commandslen = sizeof(commandHelp)/sizeof(struct commandHelp);
+ int groupslen = sizeof(commandGroups)/sizeof(char*);
+ int i, len, pos = 0;
+ helpEntry tmp;
+
+ helpEntriesLen = len = commandslen+groupslen;
+ helpEntries = malloc(sizeof(helpEntry)*len);
+
+ for (i = 0; i < groupslen; i++) {
+ tmp.argc = 1;
+ tmp.argv = malloc(sizeof(sds));
+ tmp.argv[0] = sdscatprintf(sdsempty(),"@%s",commandGroups[i]);
+ tmp.full = tmp.argv[0];
+ tmp.type = CLI_HELP_GROUP;
+ tmp.org = NULL;
+ helpEntries[pos++] = tmp;
+ }
+
+ for (i = 0; i < commandslen; i++) {
+ tmp.argv = sdssplitargs(commandHelp[i].name,&tmp.argc);
+ tmp.full = sdsnew(commandHelp[i].name);
+ tmp.type = CLI_HELP_COMMAND;
+ tmp.org = &commandHelp[i];
+ helpEntries[pos++] = tmp;
+ }
+}
+