use std::{
    fs::File,
    io::{BufRead, BufReader},
    path::Path,
};

#[derive(Clone)]
pub struct Preset {
    pub name: String,
    pub args: Vec<String>,
}
pub type Presets = Vec<Preset>;
pub fn from<P: AsRef<Path>>(path: P) -> Presets {
    let mut prs: Presets = Vec::new();

    let f = File::open(path).unwrap();
    let f = BufReader::new(f);

    for ln in f.lines() {
        let ln = ln.unwrap();
        let (name, args) = ln.split_once(": ").unwrap();
        prs.push(Preset {
            name: name.clone().to_string(),
            args: shellwords::split(args.clone()).unwrap(),
        });
    }

    prs
}
