2019-04-22 22:00:40 +02:00
|
|
|
#include <QCommandLineParser>
|
2019-04-20 23:31:14 +02:00
|
|
|
#include "commandsearch.h"
|
2019-04-22 22:00:40 +02:00
|
|
|
#include "databasefactory.h"
|
|
|
|
#include "logger.h"
|
2019-04-20 23:31:14 +02:00
|
|
|
|
2019-04-22 22:00:40 +02:00
|
|
|
int CommandSearch::handle(QStringList arguments)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addOptions({
|
2019-08-19 21:09:03 +02:00
|
|
|
{ { "r", "reverse" }, "Print most-recent changed files first. This is short for adding \"sort:(mtime asc)\" to the query." },
|
2019-04-22 22:00:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.process(arguments);
|
2019-08-19 21:09:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
QStringList files = parser.positionalArguments();
|
|
|
|
QString queryStrings = files.join(' ');
|
|
|
|
QSSQuery query = QSSQuery::build(queryStrings);
|
2019-04-22 22:00:40 +02:00
|
|
|
bool reverse = parser.isSet("reverse");
|
|
|
|
if(reverse)
|
|
|
|
{
|
2019-08-19 21:09:03 +02:00
|
|
|
SortCondition sc;
|
|
|
|
sc.field = FILE_MTIME;
|
|
|
|
sc.order = ASC;
|
|
|
|
query.addSortCondition(sc);
|
2019-04-22 22:00:40 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 21:09:03 +02:00
|
|
|
auto results = dbService->search(query);
|
2019-04-22 22:00:40 +02:00
|
|
|
|
|
|
|
for(SearchResult &result : results)
|
|
|
|
{
|
|
|
|
Logger::info() << result.fileData.absPath << endl;
|
|
|
|
}
|
|
|
|
|
2020-05-24 15:37:47 +02:00
|
|
|
return 0;
|
2019-04-22 22:00:40 +02:00
|
|
|
}
|