A small, type-safe command-line parser for C++23 modules —
import mcpplibs.cmdline;
中文 | English
Declare a command tree once; the parser, help, completions and the per-command dispatch read the same declarations. Arguments and option values are checked where they are declared, and an action returns the process status.
- C++23 module — one import, no headers.
- Subcommands at any depth — an
actiongets its ownParsedArgs; a command without one leaves the run to its nearest ancestor. - Global options — a flag parses at any depth and is copied into the parse.
- Checked values —
values({...})is a closed set;value_type<T>()checks a number withstd::from_chars;value_as<T>()reads it back. - Help that is a list —
.group()headings,.help_options({.order, .ungrouped, .groups_as_sections}),.help_epilogue(); the help, the completion candidates and the "a subcommand is required" message agree. - Shell completions —
app.completion(); the program answers__completefrom its own tree, and the bash/zsh/fish/PowerShell adapters carry no command list. - Flags answered before the action —
answer_flag(name, help, fn);parse→answer_flags(parsed)→ the action.--helpstill wins. - Agent Skills (optional) —
agent-skillsfeature +import mcpplibs.cmdline.agent_skills;. The default is build-time:mcpplibs.mplugin.cmdlinerendersdocs/<app>-skillsinto a C++ module (<app>.skills) whosesheet[]table is in the binary. No header is generated; the developer only imports the module. A runtime filesystem fallback exists (install_runtime) but is not recommended for a release. - Build helper —
mcpp/cmdline/is a separate build package (mcpplibs.mplugin.cmdline), re-exported by this one, so a consumer'sbuild.mcppimports it with no second dependency. It writes a module and adds it withmcpp::source; no include path, no header.
C++23 modules and mcpp. There is no xmake path.
mcpp build
mcpp test
mcpp build --features agent-skills # the optional runtime moduleThe library's own tests are gtest cases under tests/; fixtures/skills is a small program whose
build.mcpp renders three documents into fixture.skills and answers them — no header.
import std;
import mcpplibs.cmdline;
using namespace mcpplibs::cmdline;
int main(int argc, char* argv[]) {
App app("hello");
app.version("1.0.0")
.description("say hello")
.option("name").short_name('n').takes_value().value_name("NAME").help("who to greet")
.action([](const ParsedArgs& p) {
std::println("hello, {}", p.value("name").value_or("world"));
});
return app.run(argc, argv);
}Two sections, each command one line:
App app("tool");
app.help_options({.order = HelpOrder::alphabetical, .groups_as_sections = true});
app.subcommand(App("run").group("SUBCOMMANDS").description("run a job"));
app.subcommand(App("self").group("SELF MANAGEMENT").description("manage the tool"));--agent-skill-doc from a build-time module (the recommended default):
// build.mcpp
import mcpplibs.mplugin.cmdline;
int main() {
mcpplibs::mplugin::cmdline::options o;
o.app = "myapp", o.module_name = "myapp.skills", o.name_space = "myapp::skills";
return mcpplibs::mplugin::cmdline::embed(o) ? 0 : 1;
}// src/skills.cppm — no header: the generated module is imported
export module myapp.install;
import mcpplibs.cmdline;
import mcpplibs.cmdline.agent_skills;
import myapp.skills; // generated by build.mcpp
export void install(mcpplibs::cmdline::App& app) {
mcpplibs::cmdline::agent_skills::install_default(app, myapp::skills::sheets,
{.root_commands = {"run", "self"}, .self_commands = {"version"}});
}The fallback for development, never the default: install_runtime(app, {.root = "docs/myapp-skills", ...})
reads the same layout from disk at install time.
docs/api.md— the API, option by option.examples/— programs to copy.LICENSE— Apache-2.0.