Subcommands
Structured CLIs.
What are subcommands?
Subcommands let one binary expose several actions, like git commit and git push.
- Each subcommand has its own arguments
- The structure scales as your CLI grows
clap models these with nested Command values.
Adding a subcommand
Attach a child command with .subcommand(). The parent becomes a dispatcher.
use clap::Command;
fn main() {
Command::new("todo")
.subcommand(Command::new("add"))
.subcommand(Command::new("list"))
.get_matches();
}All lessons in this course
- clap Basics
- Subcommands
- Derive API
- Validation and Help