Cleanup CLI includes across all components

* Remove unused include files
* Move includes out of widely shared headers (reduced rebuild time)
* Consolidate code for Analyze command
This commit is contained in:
Jonathan White 2021-02-20 08:41:47 -05:00
parent dc496fd1d9
commit be3e77d721
33 changed files with 79 additions and 232 deletions

View file

@ -16,16 +16,14 @@
*/
#include "Analyze.h"
#include "cli/Utils.h"
#include "Utils.h"
#include "core/Group.h"
#include "core/HibpOffline.h"
#include "core/Tools.h"
#include <QCommandLineParser>
#include <QFile>
#include <QString>
#include "cli/TextStream.h"
#include "core/Group.h"
#include "core/Tools.h"
const QCommandLineOption Analyze::HIBPDatabaseOption = QCommandLineOption(
{"H", "hibp"},
@ -84,23 +82,21 @@ int Analyze::executeWithDatabase(QSharedPointer<Database> database, QSharedPoint
}
}
for (auto& finding : findings) {
printHibpFinding(finding.first, finding.second, out);
for (const auto& finding : findings) {
const auto entry = finding.first;
auto count = finding.second;
QString path = entry->title();
for (auto g = entry->group(); g && g != g->database()->rootGroup(); g = g->parentGroup()) {
path.prepend("/").prepend(g->name());
}
if (count > 0) {
out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
} else {
out << QObject::tr("Password for '%1' has been leaked!", "", count).arg(path) << endl;
}
}
return EXIT_SUCCESS;
}
void Analyze::printHibpFinding(const Entry* entry, int count, QTextStream& out)
{
QString path = entry->title();
for (auto g = entry->group(); g && g != g->database()->rootGroup(); g = g->parentGroup()) {
path.prepend("/").prepend(g->name());
}
if (count > 0) {
out << QObject::tr("Password for '%1' has been leaked %2 time(s)!", "", count).arg(path).arg(count) << endl;
} else {
out << QObject::tr("Password for '%1' has been leaked!", "", count).arg(path) << endl;
}
}