Skip to main content

Examples Overview

The repository ships a set of focused programs under examples/. Each one is small enough to copy into a project, but specific enough to answer "how do I do this with cli20?" without digging through tests.

Example Order​

  1. Simple API
    The smallest useful typed-schema CLI: help, a flag, an option, and a required positional.
  2. Subcommands
    Nested commands with their own help output and behavior.
  3. Validation Parse-time checks for numbers, names, and filesystem arguments.
  4. Relations Schema-level relationships such as groups, conflicts, and depends_on.
  5. Bind Write values directly into existing variables.
  6. Callback Entry Point Fill application state during parsing, then call the real entry point.
  7. Advanced Lower-level composition with explicit conversion, validation, and packing steps.
  8. Custom Action Full struct-based action definition with accepts_input, after_type, and storage_type.
  9. Git A command-heavy CLI inspired by clap's git example, including nested subcommands.
  10. Compiler Wrapper Short-cluster flags, negatable key-value options, and std::map storage with insert_or_assign.
  11. Distribution and Platform Examples Single-header usage, C++20 modules, and the Windows Unicode sample used by CI.
  12. Env Fallback Populate options from environment variables with the same conversion and validation pipeline.

Building​

cmake -B build
cmake --build build

Each source file becomes an executable with the same base name under build/examples/.