From f519cbbd79a0a8918331e0f4e7c5ae8b48c19bc2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 2 Jun 2021 21:54:34 +0000 Subject: refactor(cli): new subcommand matching format --- .nitrous/check/invalid.txt | 2 ++ .nitrous/check/valid.txt | 0 .nitrous/codes.txt | 2 ++ src/cli.rs | 78 ++++++++++++++++++++++++---------------------- 4 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 .nitrous/check/invalid.txt create mode 100644 .nitrous/check/valid.txt create mode 100644 .nitrous/codes.txt diff --git a/.nitrous/check/invalid.txt b/.nitrous/check/invalid.txt new file mode 100644 index 0000000..03401f4 --- /dev/null +++ b/.nitrous/check/invalid.txt @@ -0,0 +1,2 @@ +sDEsEecZpXFYQOm7 +HTU8AnniCTB1XOhj diff --git a/.nitrous/check/valid.txt b/.nitrous/check/valid.txt new file mode 100644 index 0000000..e69de29 diff --git a/.nitrous/codes.txt b/.nitrous/codes.txt new file mode 100644 index 0000000..03401f4 --- /dev/null +++ b/.nitrous/codes.txt @@ -0,0 +1,2 @@ +sDEsEecZpXFYQOm7 +HTU8AnniCTB1XOhj diff --git a/src/cli.rs b/src/cli.rs index 3b1046d..1dd4631 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,49 +37,51 @@ impl Cli { let debug = matches.is_present("debug"); - if matches.is_present("generate") { - Nitrous::generate( - matches - .subcommand_matches("generate") - .unwrap() - .value_of("amount") - .unwrap() - .to_string() - .parse::() - .unwrap(), - debug, - ); - } else if matches.is_present("check") { - Nitrous::check( - { - let argument = matches - .subcommand_matches("check") + match matches.subcommand() { + ("generate", _) => + Nitrous::generate( + matches + .subcommand_matches("generate") .unwrap() - .value_of("file"); - if argument.is_some() { - argument.unwrap() - } else if std::fs::File::open(".nitrous/codes.txt").is_err() { - panic!("cannot open nitrous generated codes.txt"); - } else { - ".nitrous/codes.txt" - } - }, - debug, - ProxyType::from_str( + .value_of("amount") + .unwrap() + .to_string() + .parse::() + .unwrap(), + debug, + ), + ("check", _) => + Nitrous::check( + { + let argument = matches + .subcommand_matches("check") + .unwrap() + .value_of("file"); + if argument.is_some() { + argument.unwrap() + } else if std::fs::File::open(".nitrous/codes.txt").is_err() { + panic!("cannot open nitrous generated codes.txt"); + } else { + ".nitrous/codes.txt" + } + }, + debug, + ProxyType::from_str( + matches + .subcommand_matches("check") + .unwrap() + .value_of("proxy_type") + .unwrap(), + ) + .unwrap(), matches .subcommand_matches("check") .unwrap() - .value_of("proxy_type") - .unwrap(), + .value_of("proxy_list") + .unwrap_or("null"), ) - .unwrap(), - matches - .subcommand_matches("check") - .unwrap() - .value_of("proxy_list") - .unwrap_or("null"), - ) - .await; + .await, + _ => unreachable!(), } } -- cgit v1.2.3