Introduction
AnCH CLI library aims to provide facilities for parsing CLI arguments and CLI formatter
Prerequisites
AnCH CLI is a standalone library for now
Installation
CMake target anch::cli:
find_package(Anch REQUIRED)
target_link_libraries(my-app PRIVATE anch::cli)
See installation.
Conception
AnCH CLI library main class is: ArgHandler.
AnCH CLI library contains common bindings in cli/utils.hpp : invalid values (numbers which are empty, malformed or out of range, files which can not be opened) raise std::invalid_argument , reported by ArgHandler::handle .
An option value is always the next argument (-p value or --plop value ): --plop=value and -pvalue forms are not supported.
Multiple positional argument has to be the last positional argument. Options without value can be repeated ; options with value can be repeated only when they are declared as multi .
The first -- ends options (POSIX convention): next arguments, -- included, are positional arguments.
Console formatting (Formatter) is disabled when standard output is not a terminal, when NO_COLOR environment variable is set and not empty, when ANCH_CLI_NO_FMT is 1 or with --no-term-fmt option.
Examples
Generate and parse CLIs:
struct Options {
bool verbose = false;
std::optional<std::string> str;
std::optional<std::string> str2;
std::optional<std::string> pos;
std::optional<std::string> pos2;
std::vector<std::string> multPos;
};
int
main(int argc, char** argv) {
.name = "my-app",
.version = "1.0.0",
.author = "John Doe",
.copyright = "Copyright (C) 2026 John Doe",
.licence = "WTFPL 2.0",
.banner = "My application"
};
Options opts;
{
ArgHandler handler(application, {
{.handler =
anch::cli::bindTrue(opts.verbose), .sopt =
'v', .lopt =
"verbose", .description =
"Verbose mode"},
{.handler =
anch::cli::bindStr(opts.str), .sopt =
'p', .lopt =
"plop", .value =
true, .name =
"trestreslong", .description =
"plop arg", .example =
"PLOP!!!"},
{.handler =
anch::cli::bindStr(opts.str2), .lopt =
"plip", .value =
true, .description =
"plip arg"},
{.handler =
anch::cli::bindStr(opts.pos), .value =
true, .name =
"POS1", .description =
"pos"},
{.handler =
anch::cli::bindStr(opts.pos2), .value =
true, .name =
"POS2", .description =
"pos2"},
{.handler =
anch::cli::bindCol(opts.multPos), .value =
true, .name =
"POSM", .multi =
true, .description =
"pos-mult"}
});
handler.printBanner(std::cerr);
handler.handle(argc, argv);
}
std::cout << "POS1=" << opts.pos.value() << " POS2=" << opts.pos2.value() << " POSM=" << opts.multPos.size() << " values" << std::endl;
return 0;
}