Spark-NF/qcommandlinecommandparser

Parser based on Qt's QCommandLineParser that adds support for commands.

★ 0Forks 0C++GitHub ↗Compare

README

QCommandLineCommandParser

About

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

Authors

License

The script is licensed under the Apache License 2.0.

Usage

Example

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

Root parser

// 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();

Command parser

// 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);

Included vendor files

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.

Contributors

Spark-NF

Issues