https://github.com/llvmparty/args
Minimal header-only C++11 argument parser library for simple command line tools.
https://github.com/llvmparty/args
Last synced: 2 months ago
JSON representation
Minimal header-only C++11 argument parser library for simple command line tools.
- Host: GitHub
- URL: https://github.com/llvmparty/args
- Owner: LLVMParty
- License: bsl-1.0
- Created: 2024-10-13T09:45:15.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-02-02T13:45:21.000Z (3 months ago)
- Last Synced: 2025-02-02T14:31:05.780Z (3 months ago)
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# args
Minimal header-only C++11 argument parser library for simple command line tools.
## Usage
Fetch the project in your CMakeLists.txt:
```cmake
include(FetchContent)
FetchContent_Declare(args
GIT_REPOSITORY
"https://github.com/LLVMParty/args"
GIT_TAG
v1.2
)
FetchContent_MakeAvailable(args)
```Then inherit from `ArgumentParser` and add your flags:
```cpp
#include
#include "args.hpp"struct Arguments : public ArgumentParser
{
std::string input;
std::string output;
bool parallel = false;Arguments(int argc, const char* const* argv) : ArgumentParser("Example")
{
addPositional("input", input, "Input file", true);
addString("-output", output, "Output file");
addBool("-parallel", parallel, "Process the input on multiple threads");
parseOrExit(argc, argv);
}
};int main(int argc, char** argv)
{
Arguments args(argc, argv);
printf("input: '%s'\n", args.input.c_str());
printf("output: '%s'\n", args.output.c_str());
printf("parallel: %s\n", args.parallel ? "yes" : "no");
return EXIT_SUCCESS;
}
```