diff options
| author | Mroik <mroik@delayed.space> | 2026-09-01 22:57:51 +0200 |
|---|---|---|
| committer | Mroik <mroik@delayed.space> | 2026-09-01 22:58:01 +0200 |
| commit | 6f847476b78e28407959ebfb9bb36bdc147b27ba (patch) | |
| tree | 83ed14c6eff0557744c5e2b571436c196a57d1cf /src/main.rs | |
| parent | c8e94146606fe1ccf1a8557961ef97362429f6bf (diff) | |
Allow only one type of quote size
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs index c530dc4..00949b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,16 +14,24 @@ use std::{ use anyhow::Result; use app::App; -use clap::Parser; +use clap::{Args, Parser}; use rand::Rng; use crate::config::{Quote, get_quoter}; #[derive(Parser)] -struct Args { +struct Cli { /// Turns all text into lowercase (NOOB mode) #[arg(short, long)] lower: bool, + #[command(flatten)] + quote_size: QuoteSize, + quote: Option<String>, +} + +#[derive(Args)] +#[group(required = false, multiple = false)] +struct QuoteSize { #[arg(short, long)] short: bool, #[arg(short, long)] @@ -32,7 +40,6 @@ struct Args { long: bool, #[arg(short, long)] huge: bool, - quote: Option<String>, } fn generate_quotes(path: &Path) -> Result<Vec<String>> { @@ -55,7 +62,7 @@ fn generate_quotes(path: &Path) -> Result<Vec<String>> { #[tokio::main] async fn main() -> Result<()> { - let args = Args::parse(); + let args = Cli::parse(); let mut quote = if !stdin().is_terminal() { let mut b = Vec::new(); stdin().read_to_end(&mut b).unwrap(); @@ -73,34 +80,20 @@ async fn main() -> Result<()> { source: None, } } else { - let mut specifier = 0; - if args.short { - specifier += 1; - } - if args.medium { - specifier += 1; - } - if args.long { - specifier += 1; + let mut quoter = get_quoter()?; + if args.quote_size.short { + quoter.get_short()?; } - if args.huge { - specifier += 1; + if args.quote_size.medium { + quoter.get_medium()?; } - if specifier > 1 { - panic!("You can't use more than one quote length specifier"); + if args.quote_size.long { + quoter.get_long()?; } - 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.quote_size.huge { + quoter.get_huge()?; } + quoter.get_random()? }; if args.lower { |
