Skip to content

Commit

Permalink
Abort CLI open on error
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored and droidmonkey committed Aug 16, 2021
1 parent 0413662 commit 5e68cd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cli/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ QSharedPointer<QCommandLineParser> Command::getCommandLineParser(const QStringLi
return {};
}
if (parser->positionalArguments().size() < positionalArguments.size()) {
err << QObject::tr("Missing positional argument(s).") << "\n\n";
err << getHelpText();
return {};
}
if (parser->positionalArguments().size() > (positionalArguments.size() + optionalArguments.size())) {
err << QObject::tr("Too many arguments provided.") << "\n\n";
err << getHelpText();
return {};
}
Expand Down
11 changes: 7 additions & 4 deletions src/cli/keepassxc-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ReadlineLineReader : public LineReader
};
#endif

void enterInteractiveMode(const QStringList& arguments)
int enterInteractiveMode(const QStringList& arguments)
{
auto& err = Utils::STDERR;
// Replace command list with interactive version
Expand All @@ -118,7 +118,9 @@ void enterInteractiveMode(const QStringList& arguments)
Open openCmd;
QStringList openArgs(arguments);
openArgs.removeFirst();
openCmd.execute(openArgs);
if (openCmd.execute(openArgs) != EXIT_SUCCESS) {
return EXIT_FAILURE;
};

QScopedPointer<LineReader> reader;
#if defined(USE_READLINE)
Expand Down Expand Up @@ -165,6 +167,8 @@ void enterInteractiveMode(const QStringList& arguments)
if (currentDatabase) {
currentDatabase->releaseData();
}

return EXIT_SUCCESS;
}

int main(int argc, char** argv)
Expand Down Expand Up @@ -224,8 +228,7 @@ int main(int argc, char** argv)

QString commandName = parser.positionalArguments().at(0);
if (commandName == "open") {
enterInteractiveMode(arguments);
return EXIT_SUCCESS;
return enterInteractiveMode(arguments);
}

auto command = Commands::getCommand(commandName);
Expand Down

0 comments on commit 5e68cd2

Please sign in to comment.