Allow specifying custom exit() function

This commit is contained in:
Martchus 2016-10-30 00:37:28 +02:00
parent 438ca48cbb
commit a1189d3c3b
3 changed files with 11 additions and 3 deletions

View File

@ -111,8 +111,8 @@ set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities") set(META_APP_DESCRIPTION "Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities")
set(META_VERSION_MAJOR 4) set(META_VERSION_MAJOR 4)
set(META_VERSION_MINOR 2) set(META_VERSION_MINOR 3)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 0)
# find required 3rd party libraries # find required 3rd party libraries
include(3rdParty) include(3rdParty)

View File

@ -33,6 +33,12 @@ const char *applicationVersion = nullptr;
/// \brief Specifies the URL to the application website (used by ArgumentParser::printHelp()). /// \brief Specifies the URL to the application website (used by ArgumentParser::printHelp()).
const char *applicationUrl = nullptr; const char *applicationUrl = nullptr;
/*!
* \brief Specifies a function quit the application.
* \remarks Currently only used after printing Bash completion. Default is std::exit().
*/
void(*exitFunction)(int) = &exit;
/// \cond /// \cond
inline bool notEmpty(const char *str) inline bool notEmpty(const char *str)
@ -429,7 +435,7 @@ void ArgumentParser::readArgs(int argc, const char * const *argv)
if(completionMode) { if(completionMode) {
printBashCompletion(argc, argv, currentWordIndex, lastDetectedArgument); printBashCompletion(argc, argv, currentWordIndex, lastDetectedArgument);
exit(0); // prevent the applicaton to continue with the regular execution exitFunction(0); // prevent the applicaton to continue with the regular execution
} }
} else { } else {
// no arguments specified -> flag default argument as present if one is assigned // no arguments specified -> flag default argument as present if one is assigned

View File

@ -30,6 +30,8 @@ CPP_UTILITIES_EXPORT extern const char *applicationUrl;
::ApplicationUtilities::applicationVersion = APP_VERSION; \ ::ApplicationUtilities::applicationVersion = APP_VERSION; \
::ApplicationUtilities::applicationUrl = APP_URL ::ApplicationUtilities::applicationUrl = APP_URL
CPP_UTILITIES_EXPORT extern void(*exitFunction)(int);
class Argument; class Argument;
class ArgumentParser; class ArgumentParser;