Fix index limits mistake in manage
This commit is contained in:
parent
26b649ebae
commit
833acefbb3
@ -10,7 +10,7 @@ namespace platform {
|
|||||||
{
|
{
|
||||||
cout << Colors::RED() << message << Colors::RESET() << endl;
|
cout << Colors::RED() << message << Colors::RESET() << endl;
|
||||||
}
|
}
|
||||||
pair<char, int> CommandParser::parse(const string& color, const vector<tuple<string, char, bool>>& options, const char defaultCommand)
|
pair<char, int> CommandParser::parse(const string& color, const vector<tuple<string, char, bool>>& options, const char defaultCommand, const int maxIndex)
|
||||||
{
|
{
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
@ -36,6 +36,10 @@ namespace platform {
|
|||||||
if (all_of(line.begin(), line.end(), ::isdigit)) {
|
if (all_of(line.begin(), line.end(), ::isdigit)) {
|
||||||
command = defaultCommand;
|
command = defaultCommand;
|
||||||
index = stoi(line);
|
index = stoi(line);
|
||||||
|
if (index > maxIndex || index < 0) {
|
||||||
|
messageError("Index out of range");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
finished = true;
|
finished = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -54,6 +58,10 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
index = stoi(line);
|
index = stoi(line);
|
||||||
|
if (index > maxIndex || index < 0) {
|
||||||
|
messageError("Index out of range");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::invalid_argument& ia) {
|
catch (const std::invalid_argument& ia) {
|
||||||
messageError("Invalid value: " + line);
|
messageError("Invalid value: " + line);
|
||||||
|
@ -9,7 +9,7 @@ namespace platform {
|
|||||||
class CommandParser {
|
class CommandParser {
|
||||||
public:
|
public:
|
||||||
CommandParser() = default;
|
CommandParser() = default;
|
||||||
pair<char, int> parse(const string& color, const vector<tuple<string, char, bool>>& options, const char defaultCommand);
|
pair<char, int> parse(const string& color, const vector<tuple<string, char, bool>>& options, const char defaultCommand, const int maxIndex);
|
||||||
char getCommand() const { return command; };
|
char getCommand() const { return command; };
|
||||||
int getIndex() const { return index; };
|
int getIndex() const { return index; };
|
||||||
private:
|
private:
|
||||||
|
@ -98,10 +98,6 @@ namespace platform {
|
|||||||
{
|
{
|
||||||
// Show a dataset result inside a report
|
// Show a dataset result inside a report
|
||||||
auto data = results.at(index).load();
|
auto data = results.at(index).load();
|
||||||
if (idx < 0 or idx >= static_cast<int>(data["results"].size())) {
|
|
||||||
cout << "Invalid index" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cout << Colors::YELLOW() << "Showing " << results.at(index).getFilename() << endl;
|
cout << Colors::YELLOW() << "Showing " << results.at(index).getFilename() << endl;
|
||||||
ReportConsole reporter(data, compare, idx);
|
ReportConsole reporter(data, compare, idx);
|
||||||
reporter.show();
|
reporter.show();
|
||||||
@ -160,9 +156,9 @@ namespace platform {
|
|||||||
auto parser = CommandParser();
|
auto parser = CommandParser();
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
if (indexList) {
|
if (indexList) {
|
||||||
tie(option, index) = parser.parse(Colors::GREEN(), mainOptions, 'r');
|
tie(option, index) = parser.parse(Colors::GREEN(), mainOptions, 'r', numFiles - 1);
|
||||||
} else {
|
} else {
|
||||||
tie(option, subIndex) = parser.parse(Colors::MAGENTA(), listOptions, 'r');
|
tie(option, subIndex) = parser.parse(Colors::MAGENTA(), listOptions, 'r', results.at(index).load()["results"].size() - 1);
|
||||||
}
|
}
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'q':
|
case 'q':
|
||||||
|
Loading…
Reference in New Issue
Block a user