argparse.h

- 2 mins

A simple header only command line argument parser

You can follow the project’s Github page here

Master Develop
Build Status Build Status

Table of Contents

Building With Git and CMake

Git and CMake

Make

Make

git clone https://github.com/jamolnng/argparse.git
cd argparse
mkdir build && cd build
cmake ..
make

VSCode and CMake Tools

VSCode and CMake Tools extension

TODO

Visual Studio

Visual Studio Community

TODO

Usage

#include "argparse.h"

#include <iostream>

int main(int argc, char* argv[]) {
  ArgumentParser parser("Argument parser example");
  parser.add_argument("-v",             // short argument
                      "--verbose",      // long argument
                      "Verbose level",  // description
                      false             // is required
  );
  parser.parse(argc, argv);

  if (parser.exists("verbose")) {
    switch (parser.get<unsigned int>("verbose")) {
      case 2:
        std::cout << "an even more verbose string" << std::endl;
      case 1:
        std::cout << "a verbose string" << std::endl;
      default:
        std::cout << "some verbosity" << std::endl;
    }
  }
}

Example output:

> program -v 2
an even more verbose string
a verbose string
some verbosity
> program --verbose
some verbosity

Running Tests

Make

make test

###

VSCode and CMake Tools

TODO

Visual Studio

TODO

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

GNU General Public License v3.0

Jesse C Laning

Jesse C Laning

Physicist, Programmer, Walrus

Jesse C Laning © 2023

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora