cli: CommandList: Rework, implement pattern, remove count, reverse

This commit is contained in:
Albert S. 2022-06-02 14:35:23 +02:00
父節點 51ead5e171
當前提交 45505e4447
共有 2 個文件被更改,包括 21 次插入19 次删除

查看文件

@ -7,29 +7,31 @@ int CommandList::handle(QStringList arguments)
{ {
QCommandLineParser parser; QCommandLineParser parser;
parser.addOptions({ parser.addOptions({
{{"r", "reverse"}, "Print most-recent changed files first"}, {"pattern", "Only list files from index matching the pattern, e. g. '*.txt'", "pattern"},
{{"c", "count"}, "Counts the number of paths listed"},
{"pattern", "Only list files from index matching the pattern, e. g. */.git/*", "pattern"},
}); });
parser.addHelpOption(); parser.addHelpOption();
parser.addPositionalArgument("list", "Lists paths in the index", "list [options]"); parser.addPositionalArgument("list", "Lists paths in the index", "list [options]");
parser.process(arguments); parser.process(arguments);
bool reverse = parser.isSet("reverse");
if(reverse) QString pattern = parser.value("pattern");
QVector<FileData> results;
int offset = 0;
int limit = 1000;
auto resultscount = dbService->getFiles(results, pattern, offset, limit);
while(resultscount > 0)
{ {
throw LooqsGeneralException("Reverse option to be implemented"); for(FileData &fileData : results)
}
QStringList files = parser.positionalArguments();
QString queryStrings = files.join(' ');
auto results = dbService->search(LooqsQuery::build(queryStrings, TokenType::FILTER_PATH_CONTAINS, false));
for(SearchResult &result : results)
{ {
Logger::info() << result.fileData.absPath << Qt::endl; Logger::info() << fileData.absPath << Qt::endl;
}
offset += limit;
results.clear();
resultscount = dbService->getFiles(results, pattern, offset, limit);
} }
return 0; return 0;
} }

查看文件

@ -1,5 +1,5 @@
#ifndef COMMANDSEARCH_H #ifndef COMMANDLIST_H
#define COMMANDSEARCH_H #define COMMANDLIST_H
#include "command.h" #include "command.h"
#include "../shared/sqlitesearch.h" #include "../shared/sqlitesearch.h"
@ -11,4 +11,4 @@ class CommandList : public Command
int handle(QStringList arguments) override; int handle(QStringList arguments) override;
}; };
#endif // COMMANDSEARCH_H #endif // COMMANDLIST_H