Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piotrpsz/clap
C++ library for analyzing program call arguments.
https://github.com/piotrpsz/clap
cpp cpp20
Last synced: about 2 months ago
JSON representation
C++ library for analyzing program call arguments.
- Host: GitHub
- URL: https://github.com/piotrpsz/clap
- Owner: piotrpsz
- License: mit
- Created: 2023-11-18T16:18:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-20T12:10:25.000Z (about 1 year ago)
- Last Synced: 2023-11-20T17:54:12.531Z (about 1 year ago)
- Topics: cpp, cpp20
- Language: C++
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clap
C++ library for analyzing program call arguments.
- you can use single-letter (short) arguments in the call line, e.g. -i (ignore case) -r (recursive),
- you can use longer arguments, e.g.: --icase, --resursive,
- specifying the value of the argument: -d '/Users' or -d='/Users' or --dir '/Users' lub --dir='/Users',
- if you have several arguments without values (-i and -r) you can combine them: -ir
- the text value of the argument may contain spaces: -t='ala ma kota' or --text 'ala ma kota'
## dependencies:
### fmt library
- from https://github.com/fmtlib/fmt
- install on macOS: brew install fmt
## How to add to your own project (using CMake):
- Go to the root directory of your project (I assume you have git initialized).
- Enter the command: git submodule add https://github.com/piotrpsz/clap.git
- In your project's CMakeLists.txt file, add the following:
- add_subdirectory(clap)
- target_link_libraries(your_project_name PUBLIC clap)
## Example of use:
First create a Clap object with the parameters you want:
```c++
auto clap = Clap("dirscanner v. 0.1",
Arg()
.marker("-i")
.promarker("--icase")
.ordef(false),
Arg()
.marker("-r")
.promarker("--recursive"),
Arg()
.marker("-d")
.promarker("--dir")
);
```
Then, after the program starts, call the parse function::
```c++
int main(int argn, char* argv[]) {
clap.parse(argn, argv);
...
...
}
```
And finally to get the parsing result:
```c++
if (auto directory = clap["--dir"]; directory)
std::cout << *directory << '\n';
if (auto icase = clap["-i"]; icase)
std::cout << *icase << '\n';
```
When no value is given for the argument, it receives the logical value true (that it was in the call).