extern crate argh;
use argh::{from_env, FromArgs};
use dsmsg::*;
use rand::prelude::{IteratorRandom, SliceRandom, thread_rng, ThreadRng};
#[derive(FromArgs)]
struct CommandOpts {
#[cfg(feature = "bloodborne")]
#[argh(switch)]
bb: bool,
#[cfg(feature = "demons")]
#[argh(switch)]
des: bool,
#[cfg(feature = "ds1")]
#[argh(switch)]
ds1: bool,
#[cfg(feature = "ds2")]
#[argh(switch)]
ds2: bool,
#[cfg(feature = "ds3")]
#[argh(switch)]
ds3: bool,
#[cfg(feature = "eldenring")]
#[argh(switch)]
er1: bool,
#[cfg(feature = "sekiro")]
#[argh(switch)]
sek: bool,
}
impl From<CommandOpts> for Vec<bool> {
fn from(opt: CommandOpts) -> Self {
vec![
#[cfg(feature = "bloodborne")] opt.bb,
#[cfg(feature = "demons")] opt.des,
#[cfg(feature = "ds1")] opt.ds1,
#[cfg(feature = "ds2")] opt.ds2,
#[cfg(feature = "ds3")] opt.ds3,
#[cfg(feature = "eldenring")] opt.er1,
#[cfg(feature = "sekiro")] opt.sek,
]
}
}
fn main() -> Result<(), &'static str> {
let mut rng: ThreadRng = thread_rng();
match {
let opts: Vec<bool> = Vec::from(from_env::<CommandOpts>());
if opts.iter().any(|&b| b) {
let mut filter = opts.iter().copied();
GENERATORS.iter()
.filter(move |_| filter.next().unwrap_or_default())
.choose(&mut rng)
} else {
GENERATORS.choose(&mut rng)
}
} {
Some(generate) => {
println!("{}", generate(&mut rng));
Ok(())
}
None => unsafe {
std::hint::unreachable_unchecked()
}
}
}