All Projects → lukedeo → option-parser

lukedeo / option-parser

Licence: MIT license
A Lightweight, header-only CLI option parser for C++

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to option-parser

Kotlin Argparser
Easy to use and concise yet powerful and robust command line argument parsing for Kotlin
Stars: ✭ 431 (+2593.75%)
Mutual labels:  argument-parser, option-parser, command-line-parser
Argagg
A simple C++11 command line argument parser
Stars: ✭ 180 (+1025%)
Mutual labels:  argument-parser, option-parser, command-line-parser
declarative-parser
Modern, declarative argument parser for Python 3.6+
Stars: ✭ 31 (+93.75%)
Mutual labels:  argument-parser, option-parser, command-line-parser
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+10262.5%)
Mutual labels:  argument-parser, option-parser, command-line-parser
Programoptions.hxx
Single-header program options parsing library for C++11
Stars: ✭ 112 (+600%)
Mutual labels:  argument-parser, option-parser, command-line-parser
CmdLine2
Command line argument parser (C++14)
Stars: ✭ 18 (+12.5%)
Mutual labels:  argument-parser, option-parser, command-line-parser
argparser
Simple command-line parser for C/C++ programs
Stars: ✭ 50 (+212.5%)
Mutual labels:  argument-parser, option-parser, command-line-parser
dropt
dropt is yet another C library for parsing command-line options.
Stars: ✭ 39 (+143.75%)
Mutual labels:  argument-parser, option-parser, command-line-parser
Comonicon.jl
Your best CLI generator in JuliaLang
Stars: ✭ 181 (+1031.25%)
Mutual labels:  command-line-parser, command-line-interface
Argparse
Argparse for golang. Just because `flag` sucks
Stars: ✭ 294 (+1737.5%)
Mutual labels:  argument-parser, command-line-parser
Clap
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
Stars: ✭ 7,174 (+44737.5%)
Mutual labels:  argument-parser, command-line-parser
minimist2
TypeScript/JavaScript ES6 rewrite of popular Minimist argument parser
Stars: ✭ 20 (+25%)
Mutual labels:  argument-parser, command-line-parser
Clipp
easy to use, powerful & expressive command line argument parsing for modern C++ / single header / usage & doc generation
Stars: ✭ 687 (+4193.75%)
Mutual labels:  argument-parser, option-parser
Argh
Argh! A minimalist argument handler.
Stars: ✭ 752 (+4600%)
Mutual labels:  argument-parser, command-line-parser
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+20393.75%)
Mutual labels:  argument-parser, command-line-parser
command-line-commands
Add a git-like command interface to your app.
Stars: ✭ 40 (+150%)
Mutual labels:  option-parser, command-line-parser
Console CommandLine
Full featured command line options and arguments parser.
Stars: ✭ 19 (+18.75%)
Mutual labels:  argument-parser, option-parser
go-getoptions
Fully featured Go (golang) command line option parser with built-in auto-completion support.
Stars: ✭ 41 (+156.25%)
Mutual labels:  argument-parser, option-parser
Lyra
A simple to use, composable, command line parser for C++ 11 and beyond
Stars: ✭ 238 (+1387.5%)
Mutual labels:  argument-parser, option-parser
Argumentparser
Faster, easier, more declarative parsing of command line arguments in Objective-C/Foundation.
Stars: ✭ 251 (+1468.75%)
Mutual labels:  argument-parser, command-line-parser

option-parser 💥

Build Status

A lightweight header-only option parser designed for headache-minimization in C++. Just copy-and-paste into your project and go!

Example Usage

#include "include/optionparser.h"

...


int main(int argc, char const *argv[]) {
  optionparser::OptionParser p;

  p.add_option("--number", "-n")
      .help("A number to do something with")
      .default_value(42)
      .mode(optionparser::StorageMode::STORE_VALUE);

  p.add_option("--file")
      .help("pass a list of files to load.")
      .mode(optionparser::StorageMode::STORE_MULT_VALUES)
      .required(true);

  p.add_option("--save", "-s")
      .help("Pass a file to save.")
      .dest("")
      .mode(optionparser::StorageMode::STORE_VALUE);

  p.eat_arguments(argc, argv);

  if (p.get_value("number")) {
    auto number_passed = p.get_value<int>("number");
  }

  if (p.get_value("file")) {
    auto filenames = p.get_value<std::vector<std::string>>("file");
  }

  return 0;
}

After you p.add_option("--foo", "-f"), you can chain additional statements. These include:

  • .default_value(...), to set a sensible default.
  • .dest(...), to set the metavar (i.e., the key to retrieve the value)
  • .help(...), to set a help string for that argument.
  • .mode(...), can pass one of optionparser::StorageMode::STORE_VALUE, optionparser::StorageMode::STORE_MULT_VALUES, or optionparser::StorageMode::STORE_TRUE.
  • .required(...), which can make a specific command line flag required for valid invocation.

🚧 HELP!

Some things I'd love to have but don't have the time to do (in order of priority):

  • Documentation! The library has a small surface area, but people shouldn't have to dig through a header file to find out how to do things...
  • A proper CMakeLists.txt file.
  • Subparsers, though nice, might not be possible given the library structure.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].