| name | mcpplibs-cmdline |
|---|---|
| description | Use when declaring a program's command line in C++23 - commands, options, arguments, help, completion and the --agent-skill-doc sheets. |
One declaration of a command tree is read by the parse, the help, the shell
completion and the per-command dispatch. import mcpplibs.cmdline; - no header.
[dependencies]
mcpplibs.cmdline = "0.4.0"
# with --agent-skill-doc: { version = "0.4.0", features = ["agent-skills"] }import std;
import mcpplibs.cmdline;
using namespace mcpplibs::cmdline;
int main(int argc, char* argv[]) {
App app("tool");
(void)app.version("1.0.0").description("a tool")
.help_options({.layout = HelpLayout::compact})
.option(Option("verbose").short_name('v').global().help("Print each step"));
(void)app.subcommand(App("greet").description("Greet someone")
.arg(Arg("name").required())
.option(Option("color").values({"auto", "never"}).help("When to colour"))
.example("tool greet ada")
.action([](const ParsedArgs& p) {
std::println("hello, {}", p.positional(0));
return 0;
}));
return app.run(argc, argv); // help and version: 0; a usage error: 2
}ParsedArgs:positional(i),value("name"),is_flag_set("name"),value_as<int>("jobs"),subcommand_name().- An option takes a value with
takes_value(),values({...})(a closed set),value_type<int>()(checked withfrom_chars) orvalue_hint(ValueHint::file). global()parses at any depth;multiple()collects every value.- An action returning
intis the status; a command without an action leaves the run to its nearest ancestor that has one.
group("Packages")is the section a command is listed under.help_options({.layout = HelpLayout::compact, .style = fn, .width = n}), on the root: one usage line, columns as wide as their labels,Examples:,See also:.style(HelpRole, text)adds the program's escapes (it decides whether the terminal takes them);widthbreaks prose at words. The default layout,classic, is the output of 0.3.0.level(Level::more)lists a command or option only under--help --all.example("tool greet ada"),related({"info", "index update"}).lint(app, {.max_description = 40, .max_option_help = 60})returns what is too long; call it from a test.
Sheets live in docs/<app>-skills/<app>-<command>/SKILL.md; the build helper
renders them into a module, so the binary reads no file:
// build.mcpp
import mcpplibs.mplugin.cmdline;
int main() {
mcpplibs::mplugin::cmdline::options o;
o.app = "tool", o.module_name = "tool.skills", o.name_space = "tool::skills";
return mcpplibs::mplugin::cmdline::embed(o) ? 0 : 1;
}import mcpplibs.cmdline.agent_skills;
import tool.skills;
agent_skills::install_default(app, tool::skills::sheets, {
.subjects = {{.command = "info", .form = "tool info <package> --agent-skill-doc",
.what = "the package's own sheet",
.answer = [](const ParsedArgs& p) -> std::optional<int> {
if (p.positional(0).empty()) return std::nullopt; // the sheet of info
return print_package_sheet(p.positional(0));
}}}});tool --agent-skill-docprints the root sheet and an index of the others;tool <command> --agent-skill-docthe command's.- A subject answers for what a command's argument names;
nulloptleaves the answer to the command's sheet. agent_skills::check(app, sheets, {.ascii_only = true, .subjects = ...})in a test: every command has a sheet, examples parse, eachexampleis in the sheet's## Examples, eachrelatedin its## Related, each subject's form in its sheet.
- API, option by option:
docs/api.mdin the package. - The completion protocol:
docs/completion-protocol.md.