2020-11-23 19:07:38 +00:00
|
|
|
use std::env;
|
2020-11-25 22:59:39 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use structopt::StructOpt;
|
2020-05-01 10:48:22 +00:00
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
2020-11-25 22:59:39 +00:00
|
|
|
#[structopt(
|
|
|
|
name = "git-build",
|
|
|
|
about = "Update your repositories and trigger tasks"
|
|
|
|
)]
|
2020-05-01 10:48:22 +00:00
|
|
|
pub struct Cli {
|
|
|
|
#[structopt(short = "f", long = "force")]
|
2020-05-01 11:19:33 +00:00
|
|
|
pub force: bool,
|
2020-05-01 10:48:22 +00:00
|
|
|
|
2020-11-23 19:07:38 +00:00
|
|
|
#[structopt(short = "b", long = "basedir")]
|
|
|
|
pub basedir: Option<String>,
|
|
|
|
|
2020-05-01 10:48:22 +00:00
|
|
|
//#[structopt(def)]
|
2020-05-01 11:19:33 +00:00
|
|
|
pub tasks: Vec<String>,
|
2020-05-01 10:48:22 +00:00
|
|
|
}
|
2020-11-23 19:07:38 +00:00
|
|
|
|
|
|
|
impl Cli {
|
2020-11-28 10:50:56 +00:00
|
|
|
/// 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
|
2020-11-23 19:07:38 +00:00
|
|
|
pub fn basedir(&self) -> PathBuf {
|
|
|
|
if let Some(basedir) = &self.basedir {
|
2020-11-27 18:37:46 +00:00
|
|
|
// Returns an error when the path doesn't exist
|
2020-11-25 22:59:39 +00:00
|
|
|
PathBuf::from(basedir)
|
2020-11-23 19:07:38 +00:00
|
|
|
} else {
|
|
|
|
let mut home_path = PathBuf::from(env::var("HOME").expect("No $HOME in env"));
|
|
|
|
home_path.push(".forgebuild");
|
|
|
|
home_path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|