use lexopt::{Parser, prelude::*}; const DEFAULT_ADDRESS: &str = "127.0.0.1:5500"; #[derive(Clone)] pub struct Configuration { pub address: String, } impl Default for Configuration { fn default() -> Self { Self::new() } } impl Configuration { #[must_use] pub fn new() -> Self { let mut address = DEFAULT_ADDRESS.to_string(); let mut parser = Parser::from_env(); while let Ok(Some(argument)) = parser.next() { match argument { Short('l') | Long("listen-address") => { if let Ok(value) = parser.value().and_then(|v| v.parse()) { address = value; } else { eprintln!("Warning: Invalid listen address ignored."); } } Long("help") => { println!("Usage: linea-caliente [-l|--listen-address=LISTEN_ADDRESS]"); std::process::exit(0); } _ => { eprintln!("Warning: Unknown argument ignored"); } } } Configuration { address } } }