A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/lukedeo/cmd-parser below:

lukedeo/option-parser: A Lightweight, header-only CLI option parser for C++

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

#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:

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4