The examples/ directory holds small, complete programs. Each one builds and runs on its own, so you can copy a file into your project and change it. Build them with the CLI11_BUILD_EXAMPLES CMake option, which is on by default when CLI11 is the top level project.
Read Making a git clone for a step by step walkthrough of a larger program.
Start here
minimal.cpp is the smallest program that parses and exits correctly. Use it as a starting point for a new application:
#include <CLI/CLI.hpp>
int main(int argc, char **argv) {
CLI11_PARSE(app, argc, argv);
return 0;
}
Creates a command line program, with very few defaults.
Definition App.hpp:115
simple.cpp adds options, a flag, and a version flag, and shows how to read the values and the counts back after the parse:
#include <CLI/CLI.hpp>
#include <iostream>
#include <string>
int main(int argc, char **argv) {
app.set_version_flag("--version", std::string(CLI11_VERSION));
std::string file;
CLI::Option *opt = app.add_option(
"-f,--file,file", file,
"File name");
int count{0};
CLI::Option *copt = app.add_option(
"-c,--count", count,
"Counter");
int v{0};
CLI::Option *flag = app.add_flag(
"--flag", v,
"Some flag that can be passed multiple times");
double value{0.0};
app.add_option("-d,--double", value, "Some Value");
CLI11_PARSE(app, argc, argv);
std::cout << "Working on file: " << file << ", direct count: " << app.count("--file")
<<
", opt count: " << opt->
count() <<
'\n';
std::cout << "Working on count: " << count << ", direct count: " << app.count("--count")
<<
", opt count: " << copt->
count() <<
'\n';
std::cout <<
"Received flag: " << v <<
" (" << flag->
count() <<
") times\n";
std::cout << "Some value: " << value << '\n';
return 0;
}
Definition Option.hpp:259
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:389
Options and flags
Validators
Subcommands and groups
Help output
Configuration files
Passing arguments on