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'
- from https://github.com/fmtlib/fmt
- install on macOS: brew install fmt
- 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)
First create a Clap object with the parameters you want:
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::
int main(int argn, char* argv[]) {
clap.parse(argn, argv);
...
...
}
And finally to get the parsing result:
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).