diff options
| author | Fuwn <[email protected]> | 2021-05-20 03:23:14 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-20 03:23:14 +0000 |
| commit | 7368b9ff2b98487dac4c847efb0aa8ea62a8f66e (patch) | |
| tree | f01281b004431f6d30bb76eafa8c850eff4027c8 | |
| parent | feat(readme): more additions (diff) | |
| download | nitrous-7368b9ff2b98487dac4c847efb0aa8ea62a8f66e.tar.xz nitrous-7368b9ff2b98487dac4c847efb0aa8ea62a8f66e.zip | |
feat(cli): conditional logging
| -rw-r--r-- | src/cli.rs | 14 | ||||
| -rw-r--r-- | src/nitrous.rs | 16 |
2 files changed, 25 insertions, 5 deletions
@@ -13,6 +13,11 @@ impl Cli { pub async fn execute() { let matches = Self::cli().get_matches(); + let mut debug = false; + if matches.is_present("debug") { + debug = true; + } + if matches.is_present("generate") { Nitrous::generate( matches @@ -23,6 +28,7 @@ impl Cli { .to_string() .parse::<usize>() .unwrap(), + debug, ); } else if matches.is_present("check") { Nitrous::check( @@ -31,6 +37,7 @@ impl Cli { .unwrap() .value_of("file") .unwrap(), + debug, ) .await; } @@ -56,5 +63,12 @@ impl Cli { .index(1), ), ]) + .arg(Arg::with_name("debug") + .long("debug") + .short("d") + .takes_value(false) + .multiple(false) + .global(true) + ) } } diff --git a/src/nitrous.rs b/src/nitrous.rs index 429cd2e..8264c05 100644 --- a/src/nitrous.rs +++ b/src/nitrous.rs @@ -23,7 +23,7 @@ impl Nitrous { fn initialize() { let _ = create_dir("nitrous"); } - pub fn generate(amount: usize) { + pub fn generate(amount: usize, debug: bool) { Self::initialize(); let mut codes = File::create("nitrous/codes.txt").unwrap(); @@ -36,11 +36,13 @@ impl Nitrous { .collect::<String>(); writeln!(codes, "{}", code).unwrap(); - info!("{}", code,) + if debug { + info!("{}", code,); + } } } - pub async fn check(codes_file_name: &str) { + pub async fn check(codes_file_name: &str, debug: bool) { Self::initialize(); let _ = create_dir("nitrous/check/"); @@ -62,10 +64,14 @@ impl Nitrous { if status == 200 { writeln!(valid, "{}", code).unwrap(); - info!("{}", code); + if debug { + info!("{}", code); + } } else { writeln!(invalid, "{}", code).unwrap(); - error!("{}", code); + if debug { + error!("{}", code); + } } } } |