mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-01-04 10:05:33 -05:00
CLI: Use stderr for password prompt
Fixes #3398. Convert to QTextStream for all CLI IO and greatly improve CLI tests * Completely overhaul CLI tests to be much more streamlined and easy to read. Removed unnecessary code blocks by using existing functions. Co-authored-by: Emma Brooks <me@pluvano.com>
This commit is contained in:
parent
612f8d2e5b
commit
485852c9db
30 changed files with 938 additions and 1407 deletions
|
|
@ -61,9 +61,8 @@ Merge::Merge()
|
|||
|
||||
int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
|
||||
{
|
||||
TextStream outputTextStream(parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
|
||||
QIODevice::WriteOnly);
|
||||
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
|
||||
auto& out = parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT;
|
||||
auto& err = Utils::STDERR;
|
||||
|
||||
const QStringList args = parser->positionalArguments();
|
||||
|
||||
|
|
@ -76,8 +75,7 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer
|
|||
!parser->isSet(Merge::NoPasswordFromOption),
|
||||
parser->value(Merge::KeyFileFromOption),
|
||||
parser->value(Merge::YubiKeyFromOption),
|
||||
parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
|
||||
Utils::STDERR);
|
||||
parser->isSet(Command::QuietOption));
|
||||
if (!db2) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
@ -85,7 +83,7 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer
|
|||
db2 = QSharedPointer<Database>::create();
|
||||
QString errorMessage;
|
||||
if (!db2->open(fromDatabasePath, database->key(), &errorMessage, false)) {
|
||||
errorTextStream << QObject::tr("Error reading merge file:\n%1").arg(errorMessage);
|
||||
err << QObject::tr("Error reading merge file:\n%1").arg(errorMessage);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
@ -94,19 +92,18 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer
|
|||
QStringList changeList = merger.merge();
|
||||
|
||||
for (auto& mergeChange : changeList) {
|
||||
outputTextStream << "\t" << mergeChange << endl;
|
||||
out << "\t" << mergeChange << endl;
|
||||
}
|
||||
|
||||
if (!changeList.isEmpty() && !parser->isSet(Merge::DryRunOption)) {
|
||||
QString errorMessage;
|
||||
if (!database->save(&errorMessage, true, false)) {
|
||||
errorTextStream << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl;
|
||||
err << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
outputTextStream << QObject::tr("Successfully merged %1 into %2.").arg(fromDatabasePath, toDatabasePath)
|
||||
<< endl;
|
||||
out << QObject::tr("Successfully merged %1 into %2.").arg(fromDatabasePath, toDatabasePath) << endl;
|
||||
} else {
|
||||
outputTextStream << QObject::tr("Database was not modified by merge operation.") << endl;
|
||||
out << QObject::tr("Database was not modified by merge operation.") << endl;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue