cofyc/argparse
FreeCommand-line arguments parsing library.
FreeFree tier
About cofyc/argparse
A command line arguments parsing library in C (compatible with C++), inspired by Python's argparse module and git's parse-options. It provides a high-level interface for defining what arguments a program expects, automatically handles parsing of optional and positional arguments, generates informative help and usage messages, and reports errors for invalid inputs. Supports boolean options, options with mandatory or optional arguments, short and long options, short option bundling, and a '--' separator. Licensed under MIT.
Key Features
Handles both optional and positional arguments
Automatically produces highly informative usage and help messages
Issues clear errors when invalid arguments are provided
Supports boolean options, options with mandatory argument, and options with optional argument
Supports short options (single dash) and long options (double dash)
Short options may be bundled (e.g., -a -b as -ab)
Options are case-sensitive
Uses '--' to separate options from positional arguments
Inspired by Python's argparse and git's parse-options
Written in C, compatible with C++
Pros & Cons
Pros
- High-level API simplifies argument parsing compared to getopt
- Inspired by well-known libraries (Python argparse, git parse-options) for familiarity
- MIT license allows unrestricted use, modification, and distribution
- Handles both optional and positional arguments seamlessly
- Automatically generates user-friendly help and error messages
- Lightweight and self-contained (single .c and .h file)
Cons
- Limited to C and C++ (cannot be used directly in other languages)
- Only addresses command-line argument parsing, not general-purpose parsing or configuration
- Requires manual integration into project build system (CMake, Makefile provided)
Best For
Parsing command-line arguments in C/C++ programsBuilding CLI tools with robust argument validationCreating subcommand-based interfaces (e.g., git-style)Replacing traditional getopt with a higher-level APIAutomatically generating help and usage documentation for command-line tools