Giter VIP home page Giter VIP logo

qcliparser's Introduction

QCliParser

An extension of QCommandlineParser to make context based CLIs easier

Features

  • Similar API to QCommandlineParser
  • Works by creating command trees
    • each tree node can have multiple sub-nodes of any kind
    • each tree node can define additional optional arguments
    • each tree leaf can define it's own positional arguments

Installation

The package is provided via qdep, as Skycoder42/QCliParser. To use it simply:

  1. Install and enable qdep (See qdep - Installing)
  2. Add the following to your pro file:
QDEP_DEPENDS += Skycoder42/QCliParser
!load(qdep):error("Failed to load qdep feature! Run 'qdep.py prfgen --qmake $$QMAKE_QMAKE' to create it.")

Example

Assume the following application:

QCoreApplication a(argc, argv);
QCliParser parser;
parser.addVersionOption();
parser.addHelpOption();

auto leafNode = parser.addLeafNode("leaf", "a leaf command");
leafNode->addPositionalArgument("stuff", "some positional args");

auto ctxNode = parser.addContextNode("context", "a context command");
ctxNode->addOption({"option", "some extra option"});
auto subNode1 = ctxNode->addLeafNode("sub1", "the first sub command");
auto subNode2 = ctxNode->addLeafNode("sub2", "the second sub command");

parser.process(a);
if(parser.enterContext("leaf"))
	qDebug() << "leaf was called with args:" << parser.positionalArguments();
else if(parser.enterContext("context") {
	qDebug() << "option set:" << parser.isSet("option");
	if(parser.enterContext("sub1"))
		qDebug() << "context sub1";
	else if(parser.enterContext("sub2"))
		qDebug() << "context sub2";
}

Some examples of calling this with the corresponding output would be (newlines replaced by ;):

  • leaf 1 2 3: leaf was called with args: ("1", "2", "3")
  • context sub1: option set: false; context sub1
  • context --option sub2: option set: true; context sub2

For a full example, check the demo.

qcliparser's People

Contributors

skycoder42 avatar

Stargazers

wgo avatar Elliot Leung avatar Nazar avatar Aliakbar Rashidi avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

qtbucket

qcliparser's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.