2017-08-05 12:20:26 -04:00
|
|
|
/*
|
2019-06-01 17:53:40 -04:00
|
|
|
* Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
|
2017-08-05 12:20:26 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "Locate.h"
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
2018-10-28 19:55:00 +01:00
|
|
|
#include "cli/TextStream.h"
|
2017-08-05 12:20:26 -04:00
|
|
|
#include "cli/Utils.h"
|
|
|
|
#include "core/Database.h"
|
|
|
|
#include "core/Entry.h"
|
2018-11-28 11:24:12 -05:00
|
|
|
#include "core/Global.h"
|
2017-08-05 12:20:26 -04:00
|
|
|
#include "core/Group.h"
|
|
|
|
|
|
|
|
Locate::Locate()
|
|
|
|
{
|
2018-02-06 01:17:36 +01:00
|
|
|
name = QString("locate");
|
|
|
|
description = QObject::tr("Find entries quickly.");
|
2019-06-01 17:53:40 -04:00
|
|
|
positionalArguments.append({QString("term"), QObject::tr("Search term."), QString("")});
|
2017-08-05 12:20:26 -04:00
|
|
|
}
|
|
|
|
|
2019-06-01 17:53:40 -04:00
|
|
|
int Locate::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
|
2017-08-05 12:20:26 -04:00
|
|
|
{
|
|
|
|
|
2019-06-01 17:53:40 -04:00
|
|
|
const QStringList args = parser->positionalArguments();
|
|
|
|
QString searchTerm = args.at(1);
|
2019-01-16 12:32:06 -05:00
|
|
|
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
|
|
|
|
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
|
2017-08-05 12:20:26 -04:00
|
|
|
|
|
|
|
QStringList results = database->rootGroup()->locate(searchTerm);
|
|
|
|
if (results.isEmpty()) {
|
2019-01-16 12:32:06 -05:00
|
|
|
errorTextStream << "No results for that search term." << endl;
|
2018-09-29 19:00:47 +02:00
|
|
|
return EXIT_FAILURE;
|
2017-08-05 12:20:26 -04:00
|
|
|
}
|
|
|
|
|
2018-09-29 19:00:47 +02:00
|
|
|
for (const QString& result : asConst(results)) {
|
2019-01-16 12:32:06 -05:00
|
|
|
outputTextStream << result << endl;
|
2017-08-05 12:20:26 -04:00
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|