42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use std::env;
|
|
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
// To get effective user id (EUID) so that setuid works
|
|
use users::{get_effective_uid,get_user_by_uid};
|
|
// For home directory
|
|
use users::os::unix::UserExt;
|
|
|
|
#[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 owner = get_effective_uid();
|
|
let mut home_path = get_user_by_uid(owner).expect("Failed owner profile")
|
|
.home_dir().to_path_buf();
|
|
home_path.push(".forgebuild");
|
|
home_path
|
|
}
|
|
}
|
|
}
|