About tanakh/cmdline
Cmdline is a simple, header-only command line parser for C++. It provides automatic type checking for arguments, supports flags, and allows constraints like range and oneof. The parser generates usage messages automatically and handles errors gracefully. It is designed to be easy to integrate, requiring only the cmdline.h header file.
Key Features
Header-only library (single .h file)
Automatic type checking for arguments
Supports constraints: range, oneof, and default values
Boolean flag support
Automatic usage message generation
Rest arguments and footer text support
Pros & Cons
Pros
- Easy to integrate with just one header
- Automatic type safety reduces bugs
- Clear usage message output
- Supports common constraint types (range, oneof)
Cons
- Limited to C++ only
- Does not support subcommands or nested argument structures
Best For
Parsing command line arguments in C++ applicationsQuickly adding CLI options to small to medium C++ programs
FAQ
How do I add a mandatory argument?
Use the fourth parameter of the add method: set it to true for mandatory arguments.
Can I restrict options to a set of values?
Yes, use `cmdline::oneof<string>` to restrict to specific values.
How do I access boolean flags?
Boolean flags are accessed via the `exist()` method after parsing.
Does it generate help/usage messages?
Yes, the parser automatically generates a usage message when `--help` or `-?` is specified.