From 3b9863cbecd75bfff490ef1156e88cd4bea0d49e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 22 Jun 2024 03:22:00 +0900 Subject: feat: update dependencies --- src/main.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b7df568..50d7ddb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,32 +31,24 @@ fn main() -> Result<()> { } fn parse_args() -> Result { - use clap::{crate_description, crate_version, value_t, App, Arg}; + use clap::{arg, command, value_parser}; - let matches = App::new("rand-word-gen") - .version(crate_version!()) - .about(crate_description!()) + let matches = command!() .arg( - Arg::with_name("words") - .short("n") - .long("words") - .value_name("NUMBER_OF_WORDS") + arg!(-n --words "Sets number of generated words") .default_value("20") - .help("Sets number of generated words"), - ) - .arg( - Arg::with_name("prefix") - .short("p") - .long("prefix") - .value_name("PREFIX") - .default_value("") - .help("Sets prefix of generated words"), + .value_parser(value_parser!(usize)), ) + .arg(arg!(-p --prefix "Sets prefix of generated words").default_value("")) .get_matches(); - let words = value_t!(matches, "words", usize).context("'--words' must be a number")?; - let mut prefix = - value_t!(matches, "prefix", String).context("Fatal error: failed to parse '--prefix'")?; + let words = *matches + .get_one::("words") + .context("'--words' must be a number")?; + let mut prefix = matches + .get_one::("prefix") + .context("Fatal error: failed to parse '--prefix'")? + .clone(); if !prefix.bytes().all(|c| c.is_ascii_alphabetic()) { bail!("'--prefix' must be alphabetic"); } -- cgit v1.2.3-70-g09d2