| 1 |
mod parser; |
| 2 |
|
| 3 |
fn main() -> Result<(), lexopt::Error> { |
| 4 |
let args = Args::parse()?; |
| 5 |
|
| 6 |
let input = args.input.as_deref().unwrap_or( |
| 7 |
"GET / HTTP/1.1 |
| 8 |
Host: www.reddit.com |
| 9 |
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:15.0) Gecko/20100101 Firefox/15.0.1 |
| 10 |
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 |
| 11 |
Accept-Language: en-us,en;q=0.5 |
| 12 |
Accept-Encoding: gzip, deflate |
| 13 |
Connection: keep-alive |
| 14 |
|
| 15 |
", |
| 16 |
); |
| 17 |
|
| 18 |
if let Some(result) = parser::parse(input.as_bytes()) { |
| 19 |
println!(" {result:#?}"); |
| 20 |
} |
| 21 |
|
| 22 |
Ok(()) |
| 23 |
} |
| 24 |
|
| 25 |
#[derive(Default)] |
| 26 |
struct Args { |
| 27 |
input: Option<String>, |
| 28 |
} |
| 29 |
|
| 30 |
impl Args { |
| 31 |
fn parse() -> Result<Self, lexopt::Error> { |
| 32 |
use lexopt::prelude::*; |
| 33 |
|
| 34 |
let mut res = Args::default(); |
| 35 |
|
| 36 |
let mut args = lexopt::Parser::from_env(); |
| 37 |
while let Some(arg) = args.next()? { |
| 38 |
match arg { |
| 39 |
Value(input) => { |
| 40 |
res.input = Some(input.string()?); |
| 41 |
} |
| 42 |
_ => return Err(arg.unexpected()), |
| 43 |
} |
| 44 |
} |
| 45 |
Ok(res) |
| 46 |
} |
| 47 |
} |