cli: CommandSearch: Improve error handling, helptext fixes

This commit is contained in:
Albert S. 2022-06-02 14:18:03 +02:00
parent 6f11a5e662
commit 51ead5e171

Vedi File

@ -8,14 +8,19 @@ int CommandSearch::handle(QStringList arguments)
QCommandLineParser parser; QCommandLineParser parser;
parser.addOptions({ parser.addOptions({
{{"r", "reverse"}, {{"r", "reverse"},
"Print most-recent changed files first. This is short for adding \"sort:(mtime asc)\" to the query."}, "Print most-recently changed files last. This is short for adding \"sort:(mtime asc)\" to the query."},
}); });
parser.addHelpOption(); parser.addHelpOption();
parser.process(arguments); parser.process(arguments);
QStringList files = parser.positionalArguments(); QStringList terms = parser.positionalArguments();
QString queryStrings = files.join(' '); if(terms.length() == 0)
{
Logger::error() << "Please enter search terms" << Qt::endl;
return 1;
}
QString queryStrings = terms.join(' ');
LooqsQuery query = LooqsQuery::build(queryStrings, TokenType::FILTER_PATH_CONTAINS, false); LooqsQuery query = LooqsQuery::build(queryStrings, TokenType::FILTER_PATH_CONTAINS, false);
bool reverse = parser.isSet("reverse"); bool reverse = parser.isSet("reverse");
if(reverse) if(reverse)
@ -26,12 +31,20 @@ int CommandSearch::handle(QStringList arguments)
query.addSortCondition(sc); query.addSortCondition(sc);
} }
try
{
auto results = dbService->search(query); auto results = dbService->search(query);
for(SearchResult &result : results) for(SearchResult &result : results)
{ {
Logger::info() << result.fileData.absPath << Qt::endl; Logger::info() << result.fileData.absPath << Qt::endl;
} }
}
catch(LooqsGeneralException &e)
{
Logger::error() << "Exception:" << e.message << Qt::endl;
return 1;
}
return 0; return 0;
} }