https://github.com/dead-tech/argparse-cpp
Argument Parser in C++ inspired by python's argparse module
https://github.com/dead-tech/argparse-cpp
catch2 clang-format cmake conan cpp github-actions mdbook pre-commit
Last synced: about 2 months ago
JSON representation
Argument Parser in C++ inspired by python's argparse module
- Host: GitHub
- URL: https://github.com/dead-tech/argparse-cpp
- Owner: dead-tech
- License: mit
- Created: 2022-03-27T11:40:52.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-25T18:23:53.000Z (about 3 years ago)
- Last Synced: 2025-10-09T03:31:52.001Z (8 months ago)
- Topics: catch2, clang-format, cmake, conan, cpp, github-actions, mdbook, pre-commit
- Language: C++
- Homepage: https://dead-tech.github.io/argparse-cpp
- Size: 1.14 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


[](https://results.pre-commit.ci/latest/github/dead-tech/argparse-cpp/main)
# argparse-cpp
Argument Parser in C++ inspired by python's argparse module.
## Table of contents
* [Basic Example](#example)
* [Quickstart](#quickstart)
* [Conan](#using-conan-package-manager)
* [Source Code](#download-source-code-from-latest-release)
* [Header File](#downloading-the-header-file)
* [Clone Repo](#cloning-the-repo)
* [Documentation](#documentation)
* [Testing](#testing)
* [License](#license)
## Example
Simple example program that emulates an hypothetically compiler CLI.
```cpp
#include
#include
#include
#include
int main(int argc, const char **argv)
{
argparse::ArgumentParser parser(argc, argv);
parser.add_argument("files")
.set_type(argparse::ArgTypes::STRING)
.set_default("test.txt")
.set_help("Paths to the files to compile")
.set_flags(argparse::ArgFlags::REQUIRED)
.set_metavar("FILE_PATH")
.set_nargs('+');
parser.add_argument("--release", "-R")
.set_type(argparse::ArgTypes::BOOL)
.set_help("Build in release version");
const auto args = parser.parse_args();
const auto files = args.at("files").as>();
const auto is_release = args.at("--release").as();
const auto result = build_files(files, is_release);
}
```
## Quickstart
### Using conan package manager
**Starting from release [v0.1.0](https://github.com/dead-tech/argparse-cpp/releases/tag/v0.1.0) it is possible to use conan to install the header only library from the artifactory remote.**
- Create a simple conanfile.txt in the root of your project
```txt
[requires]
argparse-cpp/0.1.1@dead/stable
[generators]
cmake
```
- Move into directory where you want to build your project
```bash
$ cd
```
- Add the artifactory remote to your conan profile
```bash
$ conan remote add argparse-cpp https://argparsecpp.jfrog.io/artifactory/api/conan/argparse-cpp-conan-local
```
- Run conan install
```bash
$ conan install .. -r argparse-cpp
```
### Download source code from latest release
Click on the releases header on the right side of the GitHub page or navigate [here](https://github.com/dead-tech/argparse-cpp/releases).
Scroll down to the assets section and download the source code (zip or tar.gz).
### Downloading the header file
- Get the file through wget
```bash
$ wget https://raw.githubusercontent.com/dead-tech/argparse-cpp/main/include/argparse/argparse.hpp
```
### Cloning the repo
- Clone the repo
```bash
$ git clone https://github.com/dead-tech/argparse-cpp.git
$ cd argparse-cpp
```
- Move the header file
```bash
$ mv include/argparse.hpp
```
## Documentation
Documentation can be found [here](dead-tech.github.io/argparse-cpp).
## Testing
This project uses catch2 as a testing framework.
All the available tests can be found [here](tests/).
The following steps are what is required to run the test suite.
```bash
$ git clone https://github.com/dead-tech/argparse-cpp.git
$ cd argparse-cpp
$ mkdir build && cd build
$ conan install ..
$ cmake .. && make
$ ./argparse-cpp_tests
```
If these steps do not work properly for you see the [official docs](https://dead-tech.github.io/argparse-cpp/user_guide/running_tests.html).
## License
The project is licensed under MIT License (see [LICENSE](LICENSE)).