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

Function parseOptions

src/keydb-diagnostic-tool.cpp:704–781  ·  view source on GitHub ↗

Returns number of consumed options. */

Source from the content-addressed store, hash-verified

702
703/* Returns number of consumed options. */
704int parseOptions(int argc, const char **argv) {
705 int i;
706 int lastarg;
707 int exit_status = 1;
708
709 for (i = 1; i < argc; i++) {
710 lastarg = (i == (argc-1));
711
712 if (!strcmp(argv[i],"-c") || !strcmp(argv[i],"--clients")) {
713 if (lastarg) goto invalid;
714 config.numclients = atoi(argv[++i]);
715 } else if (!strcmp(argv[i],"--time")) {
716 if (lastarg) goto invalid;
717 config.period_ms = atoi(argv[++i]);
718 if (config.period_ms <= 0) {
719 printf("Warning: Invalid value for thread time. Defaulting to 5000ms.\n");
720 config.period_ms = 5000;
721 }
722 } else if (!strcmp(argv[i],"-h") || !strcmp(argv[i],"--host")) {
723 if (lastarg) goto invalid;
724 config.hostip = strdup(argv[++i]);
725 } else if (!strcmp(argv[i],"-p") || !strcmp(argv[i],"--port")) {
726 if (lastarg) goto invalid;
727 config.hostport = atoi(argv[++i]);
728 } else if (!strcmp(argv[i],"-s")) {
729 if (lastarg) goto invalid;
730 config.hostsocket = strdup(argv[++i]);
731 } else if (!strcmp(argv[i],"--password") ) {
732 if (lastarg) goto invalid;
733 config.auth = strdup(argv[++i]);
734 } else if (!strcmp(argv[i],"--user")) {
735 if (lastarg) goto invalid;
736 config.user = argv[++i];
737 } else if (!strcmp(argv[i],"--dbnum")) {
738 if (lastarg) goto invalid;
739 config.dbnum = atoi(argv[++i]);
740 config.dbnumstr = sdsfromlonglong(config.dbnum);
741 } else if (!strcmp(argv[i],"-t") || !strcmp(argv[i],"--threads")) {
742 if (lastarg) goto invalid;
743 config.max_threads = atoi(argv[++i]);
744 if (config.max_threads > MAX_THREADS) {
745 printf("Warning: Too many threads, limiting threads to %d.\n", MAX_THREADS);
746 config.max_threads = MAX_THREADS;
747 } else if (config.max_threads <= 0) {
748 printf("Warning: Invalid value for max threads. Defaulting to %d.\n", MAX_THREADS);
749 config.max_threads = MAX_THREADS;
750 }
751 } else if (!strcmp(argv[i],"--help")) {
752 exit_status = 0;
753 goto usage;
754 } else {
755 /* Assume the user meant to provide an option when the arg starts
756 * with a dash. We're done otherwise and should use the remainder
757 * as the command and arguments for running the benchmark. */
758 if (argv[i][0] == '-') goto invalid;
759 return i;
760 }
761 }

Callers 1

mainFunction · 0.70

Calls 1

sdsfromlonglongFunction · 0.85

Tested by

no test coverage detected