Code Monkey home page Code Monkey logo

parseman's Introduction

Parseman Library {#mainpage}

This library is a header-only C++ library meant for parsing command line arguments.

Design

This library is header-only (meaning you don't need to link against it). It's written using C++, and tested against C++20, and is likely to work with as far back as C++11. Naming conventions are Java-esque, and you can submit a pull request if you would like to change this.

Usage

You can use parseman by including <parseman/Parser.hpp> to get started. This file includes a parseman::Parser class with an enum template that allows you to specify what commands you want to search for, as well as the types of their values when applicable.

Specifying an Enum

The first thing to do, after including the appropriate headers, is to create an enum with the commands you would like to use. Technically, this does not have to be an enum but it is strongly recommended.

Converting argc and argv

Within your main function, there should be int argc, char** argv within the arguments list; these need to be converted into std::vector<std::string> or a flat std::string representing the whole command line.

Warning
Currently, a flat string is not yet supported, but there are plans to do so in the future.

Examples

#include <parseman/Parser.hpp>
#include <string>
#include <vector>

enum ExampleCmd {
    kHelp = 0,
    kVersion
};

int main(int argc, char** argv) {
    using namespace std;
    vector<string> args {};

    for (int i = 0; i < argc; i++) {
        args.push_back(string(argv[i]) + " ");
    }

    parseman::Parser p {args};

    p.setPattern(ExampleCmd::kHelp, string(".*(--help)"));
    p.setType(ExampleCmd::kHelp, typeid(bool));

    bool is_help = p.get<bool>(ExampleCmd::kHelp);

    // ...

    return 0;
}

parseman's People

Contributors

vlpatton 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.