use std::{io, path::PathBuf};

#[derive(PartialEq, Clone, Debug)]
pub struct Arguments {
    pub help: bool,
    pub init: bool,
    pub target_dir: PathBuf,
}

impl Arguments {
    fn new() -> Self {
        Self {
            help: false,
            init: false,
            target_dir: PathBuf::new(),
        }
    }
}

pub fn parse() -> io::Result<Arguments> {
    let mut a = Arguments::new();
    let mut it = std::env::args().skip(1); // skip program name

    while let Some(arg) = it.next() {
        match arg.as_str() {
            "init" => {
                a.init = true;
            }

            "help" => {
                a.help = true;
            }

            other => {
                a.target_dir = PathBuf::from(other.trim());
                break;
            }
        }
    }

    if !a.target_dir.exists() {
        a.target_dir = std::env::current_dir()?;
    }

    Ok(a)
}
