Skip to content
/ args Public

Minimal header-only C++11 argument parser library for simple command line tools.

License

Notifications You must be signed in to change notification settings

LLVMParty/args

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

args

Minimal header-only C++11 argument parser library for simple command line tools.

Usage

Fetch the project in your CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(args
    GIT_REPOSITORY
        "https://github.com/LLVMParty/args"
    GIT_TAG
        v1.0
)
FetchContent_MakeAvailable(args)

Then inherit from ArgumentParser and add your flags:

#include <cstdio>
#include "args.hpp"

struct Arguments : public ArgumentParser
{
    std::string input;
    std::string output;
    bool        parallel = false;

    Arguments(int argc, char** argv) : ArgumentParser("Example")
    {
        addPositional("input", input, "Input file", true);
        addString("-output", output, "Output file");
        addBool("-parallel", parallel, "Process the input on multiple threads");
        parseOrExit(argc, argv);
    }
};

int main(int argc, char** argv)
{
    Arguments args(argc, argv);
    printf("input: '%s'\n", args.input.c_str());
    printf("output: '%s'\n", args.output.c_str());
    printf("parallel: %s\n", args.parallel ? "yes" : "no");
    return EXIT_SUCCESS;
}

About

Minimal header-only C++11 argument parser library for simple command line tools.

Resources

License

Stars

Watchers

Forks

Languages