mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-31 16:20:22 -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
|
|
@ -118,13 +118,14 @@ private:
|
|||
|
||||
void enterInteractiveMode(const QStringList& arguments)
|
||||
{
|
||||
auto& err = Utils::STDERR;
|
||||
// Replace command list with interactive version
|
||||
Commands::setupCommands(true);
|
||||
|
||||
Open o;
|
||||
Open openCmd;
|
||||
QStringList openArgs(arguments);
|
||||
openArgs.removeFirst();
|
||||
o.execute(openArgs);
|
||||
openCmd.execute(openArgs);
|
||||
|
||||
QScopedPointer<LineReader> reader;
|
||||
#if defined(USE_READLINE)
|
||||
|
|
@ -133,12 +134,10 @@ void enterInteractiveMode(const QStringList& arguments)
|
|||
reader.reset(new SimpleLineReader());
|
||||
#endif
|
||||
|
||||
QSharedPointer<Database> currentDatabase(o.currentDatabase);
|
||||
QSharedPointer<Database> currentDatabase(openCmd.currentDatabase);
|
||||
|
||||
QString command;
|
||||
while (true) {
|
||||
TextStream errorTextStream(Utils::STDERR, QIODevice::WriteOnly);
|
||||
|
||||
QString prompt;
|
||||
if (currentDatabase) {
|
||||
prompt += currentDatabase->metadata()->name();
|
||||
|
|
@ -159,7 +158,7 @@ void enterInteractiveMode(const QStringList& arguments)
|
|||
|
||||
auto cmd = Commands::getCommand(args[0]);
|
||||
if (!cmd) {
|
||||
errorTextStream << QObject::tr("Unknown command %1").arg(args[0]) << "\n";
|
||||
err << QObject::tr("Unknown command %1").arg(args[0]) << "\n";
|
||||
continue;
|
||||
} else if (cmd->name == "quit" || cmd->name == "exit") {
|
||||
break;
|
||||
|
|
@ -186,10 +185,12 @@ int main(int argc, char** argv)
|
|||
QCoreApplication::setApplicationVersion(KEEPASSXC_VERSION);
|
||||
|
||||
Bootstrap::bootstrap();
|
||||
Utils::setDefaultTextStreams();
|
||||
Commands::setupCommands(false);
|
||||
|
||||
TextStream out(stdout);
|
||||
TextStream err(stderr);
|
||||
auto& out = Utils::STDOUT;
|
||||
auto& err = Utils::STDERR;
|
||||
|
||||
QStringList arguments;
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
arguments << QString(argv[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue