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
|
|
@ -40,23 +40,23 @@ Export::Export()
|
|||
|
||||
int Export::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
|
||||
{
|
||||
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
|
||||
TextStream out(Utils::STDOUT.device());
|
||||
auto& err = Utils::STDERR;
|
||||
|
||||
QString format = parser->value(Export::FormatOption);
|
||||
if (format.isEmpty() || format.startsWith(QStringLiteral("xml"), Qt::CaseInsensitive)) {
|
||||
QByteArray xmlData;
|
||||
QString errorMessage;
|
||||
if (!database->extract(xmlData, &errorMessage)) {
|
||||
errorTextStream << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << endl;
|
||||
err << QObject::tr("Unable to export database to XML: %1").arg(errorMessage) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
outputTextStream.write(xmlData.constData());
|
||||
out.write(xmlData.constData());
|
||||
} else if (format.startsWith(QStringLiteral("csv"), Qt::CaseInsensitive)) {
|
||||
CsvExporter csvExporter;
|
||||
outputTextStream << csvExporter.exportDatabase(database);
|
||||
out << csvExporter.exportDatabase(database);
|
||||
} else {
|
||||
errorTextStream << QObject::tr("Unsupported format %1").arg(format) << endl;
|
||||
err << QObject::tr("Unsupported format %1").arg(format) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue