use std::env; use std::path::PathBuf; use structopt::StructOpt; use home::home_dir; #[derive(Debug, StructOpt)] #[structopt( name = "forgebuild", about = "Update your repositories and trigger tasks" )] pub struct Cli { #[structopt(short = "f", long = "force")] pub force: bool, #[structopt(short = "b", long = "basedir")] pub basedir: Option, //#[structopt(def)] pub tasks: Vec, } impl Cli { /// Returns a PathBuf to the basedir. If it's a relative link, /// it's not expanded here! Panics if no basedir is provided and $HOME isn't defined pub fn basedir(&self) -> PathBuf { if let Some(basedir) = &self.basedir { // Returns an error when the path doesn't exist PathBuf::from(basedir) } else { let mut home_path = home_dir().expect("No HOME folder found."); home_path.push(".forgebuild"); home_path } } }