make symbols optional
This commit is contained in:
parent
4b19fbfed6
commit
4a01bd5faa
|
@ -5,6 +5,8 @@ pub struct Args {
|
||||||
#[arg(short, default_value_t = 16)]
|
#[arg(short, default_value_t = 16)]
|
||||||
pub length: usize,
|
pub length: usize,
|
||||||
#[arg(short)]
|
#[arg(short)]
|
||||||
|
pub symbols: bool,
|
||||||
|
#[arg(short)]
|
||||||
pub write_to_file: bool,
|
pub write_to_file: bool,
|
||||||
#[arg(short, default_value_t = String::from("generated_pwd.txt"))]
|
#[arg(short, default_value_t = String::from("generated_pwd.txt"))]
|
||||||
pub file: String,
|
pub file: String,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::Rng;
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use crate::Args;
|
use crate::Args;
|
||||||
|
@ -15,8 +15,16 @@ impl RandomString {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let char = || CHARSET[rng.gen_range(0..CHARSET.len())] as char;
|
let char = || CHARSET[rng.gen_range(0..CHARSET.len())] as char;
|
||||||
|
|
||||||
|
if args.symbols {
|
||||||
let s: String = iter::repeat_with(char).take(args.length).collect();
|
let s: String = iter::repeat_with(char).take(args.length).collect();
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
let s: String = rng
|
||||||
|
.sample_iter(&Alphanumeric)
|
||||||
|
.take(args.length)
|
||||||
|
.map(char::from)
|
||||||
|
.collect();
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue