Go to file
2024-05-17 19:25:08 +02:00
inc/flags-cpp cmake + bugfix 2024-04-25 19:23:56 +02:00
src cmake + bugfix 2024-04-25 19:23:56 +02:00
.clang-format cmake + bugfix 2024-04-25 19:23:56 +02:00
CMakeLists.txt better cmake 2024-05-17 19:25:08 +02:00
Readme.md cmake + bugfix 2024-04-25 19:23:56 +02:00

Flags for C++

This project aims to recreate the functionality of the flag package from Golang.

Usage

Create a parser

#include <flags-cpp/flags-cpp.h>

Parser parser;
or
// set the prefix and the help text
Parser parser("--", "Help:");

Declare a flag

// name, description, required, default value
std::string* x = parser.add<std::string>("myStr", "some description", true, "default value");

Parse arguments and show help text

if (!parser.parse(argc, argv))
  parser.help();

Declare a custom parser class

PARSER(MyTypeFlag, MyType, {
  // parser body
  // available variables:
  //   MyType value;      <- storage for your value
  //   std::string arg;   <- the next argument after the current flag
  set_found(true);
  try {
    value = my_parser_function(arg);
    set_found(true);
  } catch(std::exception&) {}
})

parser.set_parser<MyType>(flag_constructor_t(MyTypeFlag::make));

Built-in parsers

  • std::string
  • int (long, long long, unsigned long, unsigned long long)
  • float, double, long double
  • bool