Use ArgumentParser::parseArgsOrExit()
This commit is contained in:
parent
36bad86c6e
commit
654489cb45
|
@ -121,7 +121,7 @@ set(REQUIRED_ICONS
|
||||||
)
|
)
|
||||||
|
|
||||||
# find c++utilities
|
# find c++utilities
|
||||||
find_package(c++utilities 4.0.0 REQUIRED)
|
find_package(c++utilities 4.10.0 REQUIRED)
|
||||||
use_cpp_utilities()
|
use_cpp_utilities()
|
||||||
include(BasicConfig)
|
include(BasicConfig)
|
||||||
|
|
||||||
|
|
89
main.cpp
89
main.cpp
|
@ -30,8 +30,6 @@ using namespace Util;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// init open ssl
|
|
||||||
OpenSsl::init();
|
|
||||||
// setup argument parser
|
// setup argument parser
|
||||||
SET_APPLICATION_INFO;
|
SET_APPLICATION_INFO;
|
||||||
ArgumentParser parser;
|
ArgumentParser parser;
|
||||||
|
@ -55,52 +53,51 @@ int main(int argc, char *argv[])
|
||||||
// holds the application's return code
|
// holds the application's return code
|
||||||
int res = 0;
|
int res = 0;
|
||||||
// parse the specified arguments
|
// parse the specified arguments
|
||||||
try {
|
parser.parseArgsOrExit(argc, argv);
|
||||||
parser.parseArgs(argc, argv);
|
// init open ssl
|
||||||
if (cliArg.isPresent()) {
|
OpenSsl::init();
|
||||||
Cli::InteractiveCli cli;
|
// start either interactive CLI or GUI
|
||||||
if (fileArg.isPresent()) {
|
if (cliArg.isPresent()) {
|
||||||
cli.run(fileArg.values().front());
|
Cli::InteractiveCli cli;
|
||||||
} else {
|
if (fileArg.isPresent()) {
|
||||||
cli.run();
|
cli.run(fileArg.values().front());
|
||||||
}
|
} else {
|
||||||
} else if (qtConfigArgs.areQtGuiArgsPresent()) {
|
cli.run();
|
||||||
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
|
}
|
||||||
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
} else if (qtConfigArgs.areQtGuiArgsPresent()) {
|
||||||
QString file;
|
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
|
||||||
if (fileArg.isPresent()) {
|
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
||||||
file = QString::fromLocal8Bit(fileArg.values().front());
|
QString file;
|
||||||
}
|
if (fileArg.isPresent()) {
|
||||||
#endif
|
file = QString::fromLocal8Bit(fileArg.values().front());
|
||||||
if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
}
|
||||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
#endif
|
||||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
||||||
#else
|
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||||
CMD_UTILS_START_CONSOLE;
|
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||||
cout << "The application has not been built with Qt widgets support." << endl;
|
#else
|
||||||
#endif
|
CMD_UTILS_START_CONSOLE;
|
||||||
} else if (qtConfigArgs.qtQuickGuiArg().isPresent()) {
|
cerr << "The application has not been built with Qt widgets support." << endl;
|
||||||
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
|
#endif
|
||||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
} else if (qtConfigArgs.qtQuickGuiArg().isPresent()) {
|
||||||
#else
|
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
|
||||||
CMD_UTILS_START_CONSOLE;
|
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||||
cout << "The application has not been built with Qt quick support." << endl;
|
#else
|
||||||
#endif
|
CMD_UTILS_START_CONSOLE;
|
||||||
} else {
|
cerr << "The application has not been built with Qt quick support." << endl;
|
||||||
#if defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
#endif
|
||||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
} else {
|
||||||
#elif defined(PASSWORD_MANAGER_GUI_QTWIDGETS)
|
#if defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
||||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||||
#else
|
#elif defined(PASSWORD_MANAGER_GUI_QTWIDGETS)
|
||||||
CMD_UTILS_START_CONSOLE;
|
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||||
cout << "See --help for usage." << endl;
|
#else
|
||||||
#endif
|
CMD_UTILS_START_CONSOLE;
|
||||||
}
|
cerr << "See --help for usage." << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} catch (const Failure &ex) {
|
|
||||||
CMD_UTILS_START_CONSOLE;
|
|
||||||
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean open ssl
|
// clean open ssl
|
||||||
OpenSsl::clean();
|
OpenSsl::clean();
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue