Skip to content

jaybdub/argument_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Argument Parser

This repository contains a simple C++ header / source file for parsing command line arguments. The syntax for adding command line arguments is as follows.

    #include "argument_parser.h"
    
    ArgumentSet args;
    args.AddFlag("help").Description("print help menu").Shorthand('h');
    args.AddPositionalArgument("output").Description("output file");
    args.AddFlag("other-flag").Description("other flag").Shorthand('f');
    args.AddNamedArgument("myarg").Description("my argument").Shorthand('m').Default("default_value");
    
    int main(int argc, char * argv[]) {
        args.Parse(argc, argv);
        std::cout << args.GetArgument("myarg").GetValue() << std::endl;
        return 0;
    }

The program takes arguments using the following format

./program -hf --myarg myarg_value output_value

also,

./program -h -f --myarg myarg_value output_value

and

./program output_value

or

./program --myarg myarg_value output_value

etc.

About

C++ argument parser.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published