GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jamolnng/argparse: A simple C++ header only command line argument parser

BranchesTags
Open more actions menu

Latest commit

 

History

84 Commits
84 Commits

Folders and files

NameName
Last commit message
Last commit date
.clang-format
.clang-format
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE
LICENSE
 
 
LICENSE.Apache-2.0-with-LLVM-Exception
LICENSE.Apache-2.0-with-LLVM-Exception
 
 
LICENSE.GPL-3.0
LICENSE.GPL-3.0
 
 
README.md
README.md
 
 
argparse.h
argparse.h
 
 
example.cpp
example.cpp
 
 
tests.cpp
tests.cpp
 
 

Repository files navigation

argparse

A simple header only command line argument parser

Master Develop
Build Status Build Status

Table of Contents

  • Building With Git and CMake
    • Make
    • VSCode and CMake Tools
    • Visual Studio
  • Example
  • Usage
  • Running Tests
    • Make
    • VSCode and CMake Tools
    • Visual Studio
  • Contributing
  • License

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 <iostream>
#include <iterator>

#include "argparse.h"

using namespace argparse;

int main(int argc, const char* argv[]) {
  ArgumentParser parser("example", "Argument parser example");
  parser.add_argument()
      .names({"-v", "--verbose"})
      .description("verbose level")
      .required(true);
  parser.add_argument("-t", "--test", "test", true)
      .position(ArgumentParser::Argument::Position::LAST);
  parser.add_argument("-d", "--dtest", "dtest", true).position(0);
  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;
#ifdef __clang__
        [[clang::fallthrough]];
#endif
        // fall through
      case 1:
        std::cout << "a verbose string" << std::endl;
#ifdef __clang__
        [[clang::fallthrough]];
#endif
        // fall through
      default:
        std::cout << "some verbosity" << std::endl;
    }
  }

  if (parser.exists("test")) {
    std::cout << parser.get<std::string>("test") << std::endl;
  }

  if (parser.exists("dtest")) {
    std::cout << parser.get<std::string>("dtest") << std::endl;
  }
}

Example output:

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

> program "something" -v=1 "something else"
a verbose string
some verbosity
something else
something

> program "something" --verbose "something else"
some verbosity
something else
something

> program -h
Usage: example [options...] [t] [d]
Options:
    -v, --verbose          verbose level           (Required)
    -t, --test             test                    (Required)
    -d, --dtest            dtest                   (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

Apache-2.0-with-LLVM-Exception or GPL-3.0

About

A simple C++ header only command line argument parser

Topics

argparseargsargument-parserargument-parsingargumentsargvargv-parserclicmdline-parsercommand-linecommandlinecppcpp11cross-platformheader-onlyheaderonlyoptionoption-parseroptionsoptions-parsing

Resources

Readme
License
Activity

Stars

147 stars

Watchers

7 watching

Forks

30 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.