Terminate app appropriately on Bash completion

This commit is contained in:
Martchus 2016-11-11 12:44:11 +01:00
parent 18a3a3f0ea
commit b1987443f1
1 changed files with 16 additions and 0 deletions

View File

@ -25,11 +25,21 @@ using namespace Data;
namespace Cli {
bool terminated = false;
int statusCode = 0;
void exitApplication(int statusCode)
{
statusCode = ::Cli::statusCode;
terminated = true;
}
Application::Application() :
m_expectedResponse(0)
{
// take ownership over the global QNetworkAccessManager
networkAccessManager().setParent(this);
exitFunction = &exitApplication;
// setup argument callbacks
m_args.status.setCallback(bind(&Application::printStatus, this, _1));
@ -57,6 +67,12 @@ int Application::exec(int argc, const char * const *argv)
try {
// parse arguments
m_args.parser.readArgs(argc, argv);
// check whether application needs to be terminated due to --bash-completion argument
if(terminated) {
return statusCode;
}
m_args.parser.checkConstraints();
// handle help argument