MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / parse_cli

Function parse_cli

subprojects/llama.cpp/tests/test-backend-sampler.cpp:1033–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1031};
1032
1033static test_args parse_cli(int argc, char ** argv) {
1034 test_args out;
1035
1036 for (int i = 1; i < argc; ++i) {
1037 const char * arg = argv[i];
1038
1039 if (std::strcmp(arg, "--test") == 0) {
1040 if (i + 1 >= argc) {
1041 fprintf(stderr, "--test expects a value\n");
1042 exit(EXIT_FAILURE);
1043 }
1044 out.test = argv[++i];
1045 continue;
1046 }
1047 if (std::strncmp(arg, "--test=", 7) == 0) {
1048 out.test = arg + 7;
1049 continue;
1050 }
1051 if (std::strcmp(arg, "--model") == 0) {
1052 if (i + 1 >= argc) {
1053 fprintf(stderr, "--model expects a value\n");
1054 exit(EXIT_FAILURE);
1055 }
1056 out.model = argv[++i];
1057 continue;
1058 }
1059 if (std::strncmp(arg, "--model=", 8) == 0) {
1060 out.model = arg + 8;
1061 continue;
1062 }
1063 if (std::strcmp(arg, "--device") == 0) {
1064 if (i + 1 >= argc) {
1065 fprintf(stderr, "--device expects a value (cpu or gpu)\n");
1066 exit(EXIT_FAILURE);
1067 }
1068 out.device = argv[++i];
1069 continue;
1070 }
1071 if (std::strncmp(arg, "--device=", 9) == 0) {
1072 out.device = arg + 9;
1073 continue;
1074 }
1075 if (out.model.empty()) {
1076 out.model = arg;
1077 continue;
1078 }
1079
1080 fprintf(stderr, "Unexpected argument: %s\n", arg);
1081 exit(EXIT_FAILURE);
1082 }
1083
1084 if (out.device != "cpu" && out.device != "gpu" && out.device != "auto") {
1085 fprintf(stderr, "Invalid device '%s'. Must be 'cpu', 'gpu' or 'auto'\n", out.device.c_str());
1086 exit(EXIT_FAILURE);
1087 }
1088
1089 return out;
1090}

Callers 1

mainFunction · 0.85

Calls 1

emptyMethod · 0.65

Tested by

no test coverage detected