Giter VIP home page Giter VIP logo

argparse's Introduction

argparse

A simple header only command line argument parser

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

Example

#include "argparse.h"

#include <iostream>
#include <iterator>

using namespace argparse;

int main(int argc, const char* argv[]) {
  ArgumentParser parser("Argument parser example");
  parser.add_argument()
      .names({"-v", "--verbose"})
      .description("verbose level")
      .required(true);
  parser.enable_help();
  auto err = parser.parse(argc, argv);
  if (err) {
    std::cout << err << std::endl;
    return -1;
  }

  if (parser.exists("help")) {
    parser.print_help();
    return 0;
  }

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

Example output:

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

> program -v=1
a verbose string
some verbosity

> program --verbose
some verbosity

> program -h
Usage: program [options] 
Options:
    -v, --verbose          verbose level           (Required)
    -h, --help             Shows this page        

> program
Required argument not found: -v

Usage

TODO

TODO

  • Positional argumeents
  • More error checking
  • Think of more things to do

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

argparse's People

Contributors

jamolnng avatar stip avatar vadikrobot avatar vsirunyan avatar

Watchers

James Cloos 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.