From 8047c16558867d8c7ee10f114607e0c2ff0e67d9 Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 19 Aug 2019 21:09:03 +0200 Subject: [PATCH] cli: search: implement -r, cleanup of options that don't belong there --- cli/commandsearch.cpp | 22 ++++++++++++---------- shared/qssquery.cpp | 7 ++++++- shared/qssquery.h | 1 + 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/cli/commandsearch.cpp b/cli/commandsearch.cpp index 0eaf069..02b95f2 100644 --- a/cli/commandsearch.cpp +++ b/cli/commandsearch.cpp @@ -7,24 +7,26 @@ int CommandSearch::handle(QStringList arguments) { QCommandLineParser parser; parser.addOptions({ - { { "r", "reverse" }, "Print most-recent changed files first" }, - { "pattern", "Only delete files from index matching the pattern, e. g. */.git/*. Only applies to --deleted or standalone.", "pattern" }, + { { "r", "reverse" }, "Print most-recent changed files first. This is short for adding \"sort:(mtime asc)\" to the query." }, }); parser.addHelpOption(); - parser.addPositionalArgument("delete", "Delete paths from the index", "delete [paths...]"); - parser.process(arguments); - bool reverse = parser.isSet("reverse"); - if(reverse) - { - throw QSSGeneralException("Reverse option to be implemented"); - } QStringList files = parser.positionalArguments(); QString queryStrings = files.join(' '); - auto results = dbService->search(QSSQuery::build(queryStrings)); + QSSQuery query = QSSQuery::build(queryStrings); + bool reverse = parser.isSet("reverse"); + if(reverse) + { + SortCondition sc; + sc.field = FILE_MTIME; + sc.order = ASC; + query.addSortCondition(sc); + } + + auto results = dbService->search(query); for(SearchResult &result : results) { diff --git a/shared/qssquery.cpp b/shared/qssquery.cpp index 1555665..3bdbef0 100644 --- a/shared/qssquery.cpp +++ b/shared/qssquery.cpp @@ -21,7 +21,12 @@ const QVector &QSSQuery::getSortConditions() const QueryType QSSQuery::getQueryType() { - return static_cast(tokensMask & COMBINED); + return static_cast(tokensMask & COMBINED); +} + +void QSSQuery::addSortCondition(SortCondition sc) +{ + this->sortConditions.append(sc); } bool QSSQuery::checkParanthesis(QString expression) diff --git a/shared/qssquery.h b/shared/qssquery.h index 09f238e..190a660 100644 --- a/shared/qssquery.h +++ b/shared/qssquery.h @@ -48,6 +48,7 @@ public: const QVector & getSortConditions() const; QueryType getQueryType(); int getTokensMask() const { return tokensMask; } + void addSortCondition(SortCondition sc); static bool checkParanthesis(QString query); static QSSQuery build(QString query);