| 2150 | } |
| 2151 | |
| 2152 | static void repl(void) { |
| 2153 | sds historyfile = NULL; |
| 2154 | int history = 0; |
| 2155 | char *line; |
| 2156 | int argc; |
| 2157 | sds *argv; |
| 2158 | |
| 2159 | /* Initialize the help and, if possible, use the COMMAND command in order |
| 2160 | * to retrieve missing entries. */ |
| 2161 | cliInitHelp(); |
| 2162 | cliIntegrateHelp(); |
| 2163 | |
| 2164 | config.interactive = 1; |
| 2165 | linenoiseSetMultiLine(1); |
| 2166 | linenoiseSetCompletionCallback(completionCallback); |
| 2167 | linenoiseSetHintsCallback(hintsCallback); |
| 2168 | linenoiseSetFreeHintsCallback(freeHintsCallback); |
| 2169 | |
| 2170 | /* Only use history and load the rc file when stdin is a tty. */ |
| 2171 | if (isatty(fileno(stdin))) { |
| 2172 | historyfile = getDotfilePath(REDIS_CLI_HISTFILE_ENV,REDIS_CLI_HISTFILE_DEFAULT); |
| 2173 | //keep in-memory history always regardless if history file can be determined |
| 2174 | history = 1; |
| 2175 | if (historyfile != NULL) { |
| 2176 | linenoiseHistoryLoad(historyfile); |
| 2177 | } |
| 2178 | cliLoadPreferences(); |
| 2179 | } |
| 2180 | |
| 2181 | cliRefreshPrompt(); |
| 2182 | while((line = linenoise(context ? config.prompt : "not connected> ")) != NULL) { |
| 2183 | if (line[0] != '\0') { |
| 2184 | long repeat = 1; |
| 2185 | int skipargs = 0; |
| 2186 | char *endptr = NULL; |
| 2187 | |
| 2188 | argv = cliSplitArgs(line,&argc); |
| 2189 | |
| 2190 | /* check if we have a repeat command option and |
| 2191 | * need to skip the first arg */ |
| 2192 | if (argv && argc > 0) { |
| 2193 | errno = 0; |
| 2194 | repeat = strtol(argv[0], &endptr, 10); |
| 2195 | if (argc > 1 && *endptr == '\0') { |
| 2196 | if (errno == ERANGE || errno == EINVAL || repeat <= 0) { |
| 2197 | fputs("Invalid redis-cli repeat command option value.\n", stdout); |
| 2198 | sdsfreesplitres(argv, argc); |
| 2199 | linenoiseFree(line); |
| 2200 | continue; |
| 2201 | } |
| 2202 | skipargs = 1; |
| 2203 | } else { |
| 2204 | repeat = 1; |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | /* Won't save auth or acl setuser commands in history file */ |
| 2209 | int dangerous = 0; |
no test coverage detected