diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-08-26 11:38:21 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-08-26 11:38:21 +0200 |
| commit | 182c508be5ff9e7da747085d4c0c13022c0fab28 (patch) | |
| tree | cf6deee752a5acdb4696dda8695db8f87f89d6e9 /src/configuration.rs | |
| parent | 8cc69f354b9ed1b57eaceecf2d971c079d6698da (diff) | |
Add handshake-able version
Diffstat (limited to 'src/configuration.rs')
| -rw-r--r-- | src/configuration.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 0000000..f74d96f --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,44 @@ +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 } + } +} |