Giter Club home page Giter Club logo

arguably's Introduction

Unit Tests codecov Licence: MIT Discord Channel Twitch live status

Arguably

A simple-to-use command line argument parser written in modern C++.

Usage

You can create a parser using the builder pattern. There are three different kinds of arguments:

  • flags (true or false),
  • named parameters, and
  • optionally named parameters.

Just concatenate the parameters you need while creating the parser and finish your call with create(). Please take a look at this example:

auto parser = arguably::create_parser()
                    .optionally_named<'f', "first", "This is the first parameter", std::string>("-")
                    .named<'n', "named", "This is some named parameter", std::string>("-")
                    .optionally_named<'s', "second", "This is the second parameter", std::string>("-")
                    .flag<'o', "option", "This is some flag">()
                    .optionally_named<'t', "third", "This is the third parameter", std::string>("-")
                    .create();

parser.parse(argv);

if (parser) { // did the parsing succeed?
    std::cout << parser.get<'f'>() << "\n"; // prints the argument passed to 'f' (or the provided default value)
}

For flags, you just do:

.flag<'f', "flag", "this is the description">()

For named parameters, you just do:

.named<'n', "named", "this is the description", std::string>("default-value")

For optionally named parameters, you just do:

.optionally_named<'n', "named", "this is the description", std::string>("default-value")

Features

This library does compile-time-checks. For example, the following code won't compile:

auto parser = arguably::create_parser()
                    .flag<'a', "a_flag", "this is a description">()
                    .create();
parser.parse(argv);
std::cout << parser.get<'b'>() << "\n"; // <- won't compile, because 'b' is no valid command abbreviation

arguably's People

Contributors

mgerhold avatar

Watchers

 avatar

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.