2022-06-05 00:59:05 -04:00
|
|
|
use kakplugin::{get_selections, set_selections, KakError};
|
2022-02-21 18:30:32 -05:00
|
|
|
use rand::{seq::SliceRandom, thread_rng};
|
2022-02-21 17:23:34 -05:00
|
|
|
#[derive(clap::StructOpt, Debug)]
|
2022-03-06 21:28:16 -05:00
|
|
|
pub struct Options;
|
2022-06-05 00:59:05 -04:00
|
|
|
pub fn shuf(_options: &Options) -> Result<String, KakError> {
|
2022-07-17 21:44:42 -04:00
|
|
|
let mut selections = get_selections(None)?;
|
2022-02-21 17:23:34 -05:00
|
|
|
let mut rng = thread_rng();
|
|
|
|
|
|
|
|
selections.shuffle(&mut rng);
|
|
|
|
|
2022-03-09 20:30:41 -05:00
|
|
|
set_selections(selections.iter())?;
|
2022-02-21 17:23:34 -05:00
|
|
|
|
2022-06-05 00:59:05 -04:00
|
|
|
Ok(format!("Shuf {} selections", selections.len()))
|
2022-02-21 17:23:34 -05:00
|
|
|
}
|