diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index efb530f..cce7334 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,30 +1,41 @@ #![allow(clippy::needless_return)] mod app; +pub mod config; pub mod error; pub mod input; pub mod state; use std::{ - error::Error, fs::read_to_string, io::{IsTerminal, Read, stdin}, path::Path, }; +use anyhow::Result; use app::App; use clap::Parser; use rand::{Rng, thread_rng}; +use crate::config::{Quote, get_quoter}; + #[derive(Parser)] struct Args { /// Turns all text into lowercase (NOOB mode) #[arg(short, long)] lower: bool, + #[arg(short, long)] + short: bool, + #[arg(short, long)] + medium: bool, + #[arg(short, long)] + long: bool, + #[arg(short, long)] + huge: bool, quote: Option<String>, } -fn generate_quotes(path: &Path) -> Result<Vec<String>, Box<dyn Error>> { +fn generate_quotes(path: &Path) -> Result<Vec<String>> { let mut ris = Vec::new(); if path.is_file() { ris.push(read_to_string(path)?); @@ -43,24 +54,57 @@ fn generate_quotes(path: &Path) -> Result<Vec<String>, Box<dyn Error>> { } #[tokio::main] -async fn main() -> Result<(), Box<dyn Error>> { +async fn main() -> Result<()> { let args = Args::parse(); let mut quote = if !stdin().is_terminal() { let mut b = Vec::new(); stdin().read_to_end(&mut b).unwrap(); - String::from_utf8(b).unwrap() + Quote { + text: String::from_utf8(b)?, + source: None, + } } else if let Some(q) = &args.quote { let path = Path::new(q); let mut quotes = generate_quotes(path).unwrap(); let mut rng = thread_rng(); let chosen = rng.gen_range(0..quotes.len()); - quotes.remove(chosen) + Quote { + text: quotes.remove(chosen), + source: None, + } } else { - todo!() + let mut specifier = 0; + if args.short { + specifier += 1; + } + if args.medium { + specifier += 1; + } + if args.long { + specifier += 1; + } + if args.huge { + specifier += 1; + } + if specifier > 1 { + panic!("You can't use more than one quote length specifier"); + } + let mut quoter = get_quoter()?; + if args.short { + quoter.get_short()? + } else if args.medium { + quoter.get_medium()? + } else if args.long { + quoter.get_long()? + } else if args.huge { + quoter.get_huge()? + } else { + quoter.get_random()? + } }; if args.lower { - quote = quote.to_lowercase(); + quote.text = quote.text.to_lowercase(); } // TODO Add more options to choose quotes |
