Improved kraken_convert command line parsing

This commit is contained in:
2020-08-06 18:52:06 -07:00
parent 78172b5abc
commit 283c4e152a

View File

@@ -47,24 +47,50 @@ int main( int argc, char *argv[] )
char* output_bundle = nullptr; char* output_bundle = nullptr;
bool compile_shaders = false; bool compile_shaders = false;
char command = '\0';
for (int i = 1; i < argc && !failed; i++) { for (int i = 1; i < argc && !failed; i++) {
char *arg = argv[i]; char *arg = argv[i];
if (arg[0] == '-') { if (arg[0] == '-') {
if (command != '\0') {
// The last command is expecting a parameter, not another command.
printf("Invalid syntax. '%s' not expected after '-%c'\n", arg, command);
failed = true;
continue; continue;
} }
if (i > 1 && argv[i - 1][0] == '-') { if (arg[1] == '\0') {
char command = argv[i - 1][1]; // We received a lonely '-'
printf("Invalid syntax. '-' must be followed by a command.\n");
failed = true;
continue;
}
if (arg[2] != '\0') {
// All commands are currently one character long
printf("Unknown command: '%s'\n", arg);
failed = true;
continue;
}
command = arg[1];
switch (command) {
case 'c':
compile_shaders = true;
command = '\0';
break;
case 'o':
// Next arg will be the output path
break;
default:
printf("Unknown command: '%s'\n", arg);
failed = true;
continue;
}
continue;
}
// Process commands that receive arguments
switch (command) { switch (command) {
case 'o': case 'o':
output_bundle = arg; output_bundle = arg;
break; command = '\0';
case 'c':
compile_shaders = true;
break;
default:
printf("Unknown command: -%c\n", command);
break;
}
continue; continue;
} }
@@ -87,7 +113,7 @@ int main( int argc, char *argv[] )
} }
if (compile_shaders && !failed) { if (compile_shaders && !failed) {
printf("Compiling Shaders...\n"); printf("Compiling Shaders... ");
KrCompileAllShadersInfo compile_all_shaders_info = {}; KrCompileAllShadersInfo compile_all_shaders_info = {};
compile_all_shaders_info.sType = KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS; compile_all_shaders_info.sType = KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS;
compile_all_shaders_info.logHandle = ResourceMapping::shader_compile_log; compile_all_shaders_info.logHandle = ResourceMapping::shader_compile_log;