If your needs are simple, you might want to take a look at Argh!.
It is single header and super easy to use:
int main(int, char* argv[])
{
argh::parser cmdl(argv); // declare
if (cmdl[{ "-v", "--verbose" }]) // use immediately
std::cout << "Verbose, I am.\n";
return EXIT_SUCCESS;
}
By being unintrusive, it doesn't take over you main()
function.
From the Readme:
Philosophy
Contrary to many alternatives, argh
takes a minimalist laissez-faire approach, very suitable for fuss-less prototyping with the following rules:
The API is:
- Minimalistic but expressive:
- No getters nor binders
- Just the
[]
and ()
operators.
- Easy iteration (range-
for
too).
- You don't pay for what you don't use;
- Conversion to typed variables happens (via
std::istream >>
) on the user side after the parsing phase;
- No exceptions thrown for failures.
- Liberal BSD license;
- Single header file;
- No non-
std
dependencies.
argh
does not care about:
- How many '
-
' preceded your option;
- Which flags and options you support - that is your responsibility;
- Syntax validation: any command line is a valid (not necessarily unique) combination of positional parameters, flags and
options;
- Automatically producing a usage message.