diff --git a/src/main.cpp b/src/main.cpp index c835d9b..766ba97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,17 @@ string getSessionKey() { return key; } +void parseArgument(const string& arg, int &dayNum, bool &useTestInput, int &testFetchIndex){ + size_t tIndex = arg.find('T'); + if (tIndex == string::npos) { + dayNum = stoi(arg); + return; + } + dayNum = stoi(arg.substr(0, tIndex)); + useTestInput = true; + testFetchIndex = stoi(arg.substr(tIndex + 1)); +} + int main(int argc, char *argv[]) { auto key = getSessionKey(); @@ -64,9 +75,10 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { string arg = argv[i]; - bool useTestInput = arg.size() > 1 && arg[1] == 'T'; - int testFetchIndex = useTestInput && arg.size() > 2 ? arg[2] - '0' : 0; - int dayNum = std::stoi(arg); + bool useTestInput = false; + int testFetchIndex; + int dayNum; + parseArgument(arg, dayNum, useTestInput, testFetchIndex); cout << "Running day " << dayNum << endl; Input input = getInput(dayNum, key, useTestInput, testFetchIndex); Day *day = days[dayNum - 1];