mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-28 12:57:03 -08: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 <[email protected]>
This commit is contained in:
1 parent
612f8d2e5b
commit
485852c9db
30 files changed
+938
-1407
No files matched your search
@@ -39,8 +39,8 @@ AddGroup::~AddGroup()
|
||||
|
||||
int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<QCommandLineParser> parser)
|
||||
{
|
||||
TextStream outputTextStream(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
|
||||
auto& out = Utils::STDOUT;
|
||||
auto& err = Utils::STDERR;
|
||||
|
||||
const QStringList args = parser->positionalArguments();
|
||||
const QString& groupPath = args.at(1);
|
||||
@@ -51,13 +51,13 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin
|
||||
|
||||
Group* group = database->rootGroup()->findGroupByPath(groupPath);
|
||||
if (group) {
|
||||
errorTextStream << QObject::tr("Group %1 already exists!").arg(groupPath) << endl;
|
||||
err << QObject::tr("Group %1 already exists!").arg(groupPath) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Group* parentGroup = database->rootGroup()->findGroupByPath(parentGroupPath);
|
||||
if (!parentGroup) {
|
||||
errorTextStream << QObject::tr("Group %1 not found.").arg(parentGroupPath) << endl;
|
||||
err << QObject::tr("Group %1 not found.").arg(parentGroupPath) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ int AddGroup::executeWithDatabase(QSharedPointer<Database> database, QSharedPoin
|
||||
|
||||
QString errorMessage;
|
||||
if (!database->save(&errorMessage, true, false)) {
|
||||
errorTextStream << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
|
||||
err << QObject::tr("Writing the database failed %1.").arg(errorMessage) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!parser->isSet(Command::QuietOption)) {
|
||||
outputTextStream << QObject::tr("Successfully added group %1.").arg(groupName) << endl;
|
||||
out << QObject::tr("Successfully added group %1.").arg(groupName) << endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user