build.rs/src/cli.rs

35 lines
952 B
Rust

use std::env;
use std::path::PathBuf;
use structopt::StructOpt;
#[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<String>,
//#[structopt(def)]
pub tasks: Vec<String>,
}
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 = PathBuf::from(env::var("HOME").expect("No $HOME in env"));
home_path.push(".forgebuild");
home_path
}
}
}