use clap::App; use preftool_clap::ClapConfigExt; use preftool_clap_derive::ClapConfig; #[derive(ClapConfig)] pub struct Server { #[preftool_clap(help = "Server host")] host: String, #[preftool_clap(help = "Server port")] port: usize, #[preftool_clap(help = "Server certificate (enables TLS)")] cert: Option, } #[test] fn sets_host() { let args = vec!["test", "--host=localhost"]; let result = Server::from_cli_args(App::new("test"), args).unwrap(); assert_eq!(result.len(), 1); assert_eq!(result.get("host").unwrap(), "localhost"); assert_eq!(result.get("port"), None); } #[test] fn sets_port() { let args = vec!["test", "--port", "8080"]; let result = Server::from_cli_args(App::new("test"), args).unwrap(); assert_eq!(result.len(), 1); assert_eq!(result.get("port").unwrap(), "8080"); assert_eq!(result.get("host"), None); } #[test] fn sets_both() { let args = vec!["test", "--port", "8080", "--host=otherhost"]; let result = Server::from_cli_args(App::new("test"), args).unwrap(); assert_eq!(result.len(), 2); assert_eq!(result.get("port").unwrap(), "8080"); assert_eq!(result.get("host").unwrap(), "otherhost"); }