diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-06-22 03:22:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-06-22 03:22:00 +0900 |
| commit | 3b9863cbecd75bfff490ef1156e88cd4bea0d49e (patch) | |
| tree | 8164621b21d6336036c6ba033d93d21d46fd28dc /src/main.rs | |
| parent | b606bfd0a0d42f5c159a58b36a40a9ef5b3dd2b8 (diff) | |
| download | rand-word-gen-3b9863cbecd75bfff490ef1156e88cd4bea0d49e.tar.gz rand-word-gen-3b9863cbecd75bfff490ef1156e88cd4bea0d49e.tar.zst rand-word-gen-3b9863cbecd75bfff490ef1156e88cd4bea0d49e.zip | |
feat: update dependencies
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 32 |
1 files changed, 12 insertions, 20 deletions
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<Config> { - 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 <NUMBER_OF_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 <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::<usize>("words") + .context("'--words' must be a number")?; + let mut prefix = matches + .get_one::<String>("prefix") + .context("Fatal error: failed to parse '--prefix'")? + .clone(); if !prefix.bytes().all(|c| c.is_ascii_alphabetic()) { bail!("'--prefix' must be alphabetic"); } |
