Clap validate number range
- value_parser!
use clap::Parser; #[derive(Parser)] struct Cli { #[arg(long, value_parser = clap::value_parser!(u16).range(1024..10000))] port: u16, } fn main() { let cli = Cli::parse(); println!("PORT = {}", cli.port); }
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
use clap::Parser; #[derive(Parser)] struct Cli { #[arg(long, value_parser = clap::value_parser!(u16).range(1024..10000))] port: u16, } fn main() { let cli = Cli::parse(); println!("PORT = {}", cli.port); }