Parser based on Qt's QCommandLineParser that adds support for commands.
$ example --help
Usage: example [options] <command> [args]
Manage items
Options:
-v, --version Displays version information.
-h, --help Displays help on commandline options.
Commands:
add Add a new item
list List items$ example add --help
Usage: example add [options] <item>
Add a new item
Options:
-h, --help Displays help on commandline options.
--type <item_type> Item type
Arguments:
item The item to add- Nicolas Faure (Spark-NF)
The script is licensed under the Apache License 2.0.
You can find a full example in example/main.cpp.
It can be built and run with:
mkdir build
cd build
cmake ../example
make
./example// Create a parser
QCommandLineCommandParser parser;
// Add some commands
parser.addCommand("list", "List items");
parser.addCommand("add", "Add a new item");
// Process the arguments as usual
parser.process(qApp);
// Get the chosen command
const QString command = parser.command();// Create a parser
QCommandLineCommandParser parser;
// Set the prefix (used in help text and to remove it from positionalArguments())
parser.setPrefix({ "add" });
// Process the arguments as usual
parser.process(qApp);Due to the fact that many of the inner workings of QCommandLineParser are private but that this parser does not want to re-invent the wheel, it includes a copy of some of QCommandLineParser internal functions.
If you're using a different Qt version, you might want to update them to match.