Skip to content

Commit

Permalink
qDebug() -> cerr
Browse files Browse the repository at this point in the history
  • Loading branch information
Daoortor committed Dec 9, 2024
1 parent 2ac045d commit 3f49228
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

QTextStream cout(stdout, QIODevice::WriteOnly);
QTextStream cin(stdin, QIODevice::ReadOnly);
QTextStream cerr(stderr, QIODevice::WriteOnly);

const QString PROGRAM_NAME = "sdt-navigator";
const QString CLI_HELP_MESSAGE = R"(
Expand Down Expand Up @@ -74,7 +75,7 @@ void handleRouteCommand(const sdtmaps::TransportSystem &transportSystem, std::ve
if (!start) {
std::vector <const sdtmaps::Stop *> searchResult = transportSystem.getStopsBySubstring(startArg.c_str());
if (searchResult.empty()) {
qDebug() << "Start station '" << startArg.c_str() << "' not found\n" << Qt::flush;
cerr << "Start station '" << startArg.c_str() << "' not found\n" << Qt::flush;
return;
}
start = searchResult[0];
Expand All @@ -86,26 +87,26 @@ void handleRouteCommand(const sdtmaps::TransportSystem &transportSystem, std::ve
if (!end) {
std::vector <const sdtmaps::Stop *> searchResult = transportSystem.getStopsBySubstring(endArg.c_str());
if (searchResult.empty()) {
qDebug() << "Destination station '" << endArg.c_str() << "' not found\n" << Qt::flush;
cerr << "Destination station '" << endArg.c_str() << "' not found\n" << Qt::flush;
return;
}
end = searchResult[0];
}

QDate initDate = dateArg.empty() ? QDate::fromJulianDay(0) : QDate::fromString(dateArg.c_str(), "yyyy-MM-dd");
if (!initDate.isValid()) {
qDebug() << "Invalid date format: " << dateArg.c_str() << ". Should be yyyy-MM-dd." << Qt::flush;
cerr << "Invalid date format: " << dateArg.c_str() << ". Should be yyyy-MM-dd." << Qt::flush;
return;
}
QTime initTime = timeArg.empty() ? QTime(0, 0) : QTime::fromString(timeArg.c_str());
if (!initTime.isValid()) {
qDebug() << "Invalid time format: " << timeArg.c_str() << ". Should be HH:mm." << Qt::flush;
cerr << "Invalid time format: " << timeArg.c_str() << ". Should be HH:mm." << Qt::flush;
return;
}
QDateTime initDateTime = QDateTime(initDate, initTime);
std::optional<sdtmaps::Journey> result = pathfind(transportSystem, start->id, end->id, initDateTime);
if (!result.has_value()) {
qDebug() << "No journey found.\n" << Qt::flush;
cerr << "No journey found.\n" << Qt::flush;
return;
}
sdtmaps::Journey &journey = result.value();
Expand All @@ -126,7 +127,7 @@ void handleSearchCommand(const sdtmaps::TransportSystem &transportSystem, std::v

std::vector<const sdtmaps::Stop *> result = transportSystem.getStopsBySubstring(substringArg.c_str());
if (result.empty()) {
qDebug() << "No stops found.\n" << Qt::flush;
cout << "No stops found.\n" << Qt::flush;
return;
}
cout << "\nFound " << result.size() << " stops:\n\n";
Expand Down Expand Up @@ -198,7 +199,7 @@ int main(int argc, char** argv) {
} else if (commandName == "help") {
handleHelpCommand();
} else {
qDebug() << "Unknown command: " << commandName.c_str() << ". Type help for help." << Qt::flush;
cout << "Unknown command: " << commandName.c_str() << ". Type help for help." << Qt::flush;
}
cout << "[" + PROGRAM_NAME + "]$ " << Qt::flush;
}
Expand Down

0 comments on commit 3f49228

Please sign in to comment.