I'm trying to develop a scoring engine in C++ for vuln remediation practice development, but it's been a few years since I last touched C++, would you guys mind helping me clean up this bunch of if, else if statements, or should I just leave it as it is. All suggestions are welcome.
I tried a switch case statement because I'd been working a lot with python and bash the past few years, but I remembered that C++ only supports integers for case statements, I was wondering if perhaps I should use mappings and incorporate switch cases or if that'd make the code less readable.
#include <iostream>
struct commandLineArgs {
const char* filePath = "./tmp.yaml";
bool silenceOutput = false;
std::string runType = "";
void parseArgs (int argc, char *argv[]){
if (argc > 1){
for (int i = 1; i < argc; i++){
std::string argumentValue = std::string(argv[i]);
if (argumentValue == "--debug" || argumentValue == "-d"){
}
else if ((argumentValue == "--path" || argumentValue == "-p") && i+1 < argc){
filePath = argv[i+1];
}
else if (argumentValue == "--help" || argumentValue == "-h"){
}
else if (argumentValue == "--quiet" || argumentValue == "-q"){
silenceOutput = true;
}
else if (argumentValue == "check" || argumentValue == "s"){
runType = "check";
}
else if (argumentValue == "score" || argumentValue == "c"){
runType = "score";
}
else if (argumentValue == "readme" || argumentValue == "rd"){
runType = "readme";
}
else if (argumentValue == "encrypt" || argumentValue == "e"){
runType = "encrypt";
}
else if (argumentValue == "prompt" || argumentValue == "p"){
runType = "prompt";
}
else if (argumentValue == "info" || argumentValue == "i"){
runType = "info";
}
else if (argumentValue == "version" || argumentValue == "v"){
runType = "version";
}
else if (argumentValue == "release" || argumentValue == "r"){
runType = "release";
}
}
}
}
} cmdArgs;