main.rs (1163B)
1 mod smmry; 2 use clap::{ArgGroup, Parser}; 3 use ureq::{self, Error}; 4 5 #[derive(Parser)] 6 #[command(author, version, about, long_about = None)] 7 #[clap(group( 8 ArgGroup::new("outfmt") 9 .args(&["markdown", "text", "html"]), 10 ))] 11 struct Cli { 12 /// URL to summarize 13 url: String, 14 15 /// Output Markdown instead of HTML 16 #[arg(short, long)] 17 markdown: bool, 18 /// Output plaintext instead of HTML 19 #[arg(short, long)] 20 text: bool, 21 /// Output HTML (the default) 22 #[arg(short = 'H', long, default_value_t = true)] 23 html: bool, 24 } 25 26 fn main() { 27 let cli = Cli::parse(); 28 let outfmt = if cli.markdown { 29 smmry::OutputFmt::Markdown 30 } else if cli.text { 31 smmry::OutputFmt::Text 32 } else if cli.html { 33 smmry::OutputFmt::Html 34 } else { 35 unreachable!("Output format not set"); 36 }; 37 let data = smmry::summarize(&cli.url); 38 match data { 39 Ok(resp) => smmry::show_summary(resp, outfmt), 40 Err(Error::Status(code, response)) => { 41 println!("{} {}", code, response.status_text()) 42 } 43 Err(e) => { 44 println!("Error: {:?}", e) 45 } 46 }; 47 }