Use new argument parser API
This commit is contained in:
parent
8529dbb4bc
commit
dd7ff6ea98
|
@ -70,8 +70,12 @@ set(ICON_FILES
|
||||||
resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
|
resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(DOC_FILES
|
||||||
|
README.md
|
||||||
|
)
|
||||||
|
|
||||||
# find c++utilities
|
# find c++utilities
|
||||||
find_package(c++utilities 3.3.0 REQUIRED)
|
find_package(c++utilities 4.0.0 REQUIRED)
|
||||||
use_cpp_utilities()
|
use_cpp_utilities()
|
||||||
|
|
||||||
# find qtutilities
|
# find qtutilities
|
||||||
|
|
22
main.cpp
22
main.cpp
|
@ -36,20 +36,22 @@ int main(int argc, char *argv[])
|
||||||
SET_APPLICATION_INFO;
|
SET_APPLICATION_INFO;
|
||||||
ArgumentParser parser;
|
ArgumentParser parser;
|
||||||
parser.setIgnoreUnknownArguments(true);
|
parser.setIgnoreUnknownArguments(true);
|
||||||
// Qt configuration arguments
|
|
||||||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
|
||||||
// file argument
|
// file argument
|
||||||
Argument fileArg("file", "f", "specifies the file to be opened (or created when using --modify)");
|
Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)");
|
||||||
fileArg.setValueNames({"path"});
|
fileArg.setValueNames({"path"});
|
||||||
fileArg.setRequiredValueCount(1);
|
fileArg.setRequiredValueCount(1);
|
||||||
fileArg.setCombinable(true);
|
fileArg.setCombinable(true);
|
||||||
fileArg.setRequired(false);
|
fileArg.setRequired(false);
|
||||||
fileArg.setImplicit(true);
|
fileArg.setImplicit(true);
|
||||||
|
// Qt configuration arguments
|
||||||
|
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||||
|
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
|
||||||
// cli argument
|
// cli argument
|
||||||
Argument cliArg("interactive-cli", "i", "starts the interactive command line interface");
|
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
|
||||||
|
cliArg.setSubArguments({&fileArg});
|
||||||
// help argument
|
// help argument
|
||||||
HelpArgument helpArg(parser);
|
HelpArgument helpArg(parser);
|
||||||
parser.setMainArguments({&fileArg, &helpArg, &(qtConfigArgs.qtWidgetsGuiArg()), &(qtConfigArgs.qtQuickGuiArg()), &cliArg});
|
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg});
|
||||||
// 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
|
||||||
|
@ -57,16 +59,16 @@ int main(int argc, char *argv[])
|
||||||
parser.parseArgs(argc, argv);
|
parser.parseArgs(argc, argv);
|
||||||
if(cliArg.isPresent()) {
|
if(cliArg.isPresent()) {
|
||||||
Cli::InteractiveCli cli;
|
Cli::InteractiveCli cli;
|
||||||
if(fileArg.isPresent() && fileArg.valueCount() == 1) {
|
if(fileArg.isPresent()) {
|
||||||
cli.run(fileArg.value(0));
|
cli.run(fileArg.values().front());
|
||||||
} else {
|
} else {
|
||||||
cli.run();
|
cli.run();
|
||||||
}
|
}
|
||||||
} else if(qtConfigArgs.areQtGuiArgsPresent()) {
|
} else if(qtConfigArgs.areQtGuiArgsPresent()) {
|
||||||
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
|
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
|
||||||
QString file;
|
QString file;
|
||||||
if(fileArg.valueCount() > 0) {
|
if(fileArg.isPresent()) {
|
||||||
file = QString::fromLocal8Bit(fileArg.value(0).c_str());
|
file = QString::fromLocal8Bit(fileArg.values().front());
|
||||||
}
|
}
|
||||||
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
||||||
#ifdef GUI_QTWIDGETS
|
#ifdef GUI_QTWIDGETS
|
||||||
|
@ -93,7 +95,7 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Failure &ex) {
|
} catch(const Failure &ex) {
|
||||||
CMD_UTILS_START_CONSOLE;
|
CMD_UTILS_START_CONSOLE;
|
||||||
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue