cli: search: implement -r, cleanup of options that don't belong there
This commit is contained in:
		@@ -7,25 +7,26 @@ int CommandSearch::handle(QStringList arguments)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	QCommandLineParser parser;
 | 
						QCommandLineParser parser;
 | 
				
			||||||
	parser.addOptions({
 | 
						parser.addOptions({
 | 
				
			||||||
		{{"r", "reverse"}, "Print most-recent changed files first"},
 | 
							{{"r", "reverse"},
 | 
				
			||||||
		{"pattern",
 | 
							 "Print most-recent changed files first. This is short for adding \"sort:(mtime asc)\" to the query."},
 | 
				
			||||||
		 "Only delete files from index matching the pattern, e. g. */.git/*. Only applies to --deleted or standalone.",
 | 
					 | 
				
			||||||
		 "pattern"},
 | 
					 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	parser.addHelpOption();
 | 
						parser.addHelpOption();
 | 
				
			||||||
	parser.addPositionalArgument("delete", "Delete paths from the index", "delete [paths...]");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	parser.process(arguments);
 | 
						parser.process(arguments);
 | 
				
			||||||
	bool reverse = parser.isSet("reverse");
 | 
					 | 
				
			||||||
	if(reverse)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		throw QSSGeneralException("Reverse option to be implemented");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QStringList files = parser.positionalArguments();
 | 
						QStringList files = parser.positionalArguments();
 | 
				
			||||||
	QString queryStrings = files.join(' ');
 | 
						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)
 | 
						for(SearchResult &result : results)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,11 @@ QueryType QSSQuery::getQueryType()
 | 
				
			|||||||
	return static_cast<QueryType>(tokensMask & COMBINED);
 | 
						return static_cast<QueryType>(tokensMask & COMBINED);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void QSSQuery::addSortCondition(SortCondition sc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						this->sortConditions.append(sc);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool QSSQuery::checkParanthesis(QString expression)
 | 
					bool QSSQuery::checkParanthesis(QString expression)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QStack<QChar> open;
 | 
						QStack<QChar> open;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,6 +52,7 @@ class QSSQuery
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		return tokensMask;
 | 
							return tokensMask;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						void addSortCondition(SortCondition sc);
 | 
				
			||||||
	static bool checkParanthesis(QString query);
 | 
						static bool checkParanthesis(QString query);
 | 
				
			||||||
	static QSSQuery build(QString query);
 | 
						static QSSQuery build(QString query);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user