fix(notstrap): fix clippy warning and unwrap panics in lib extraction
This commit is contained in:
@@ -9,6 +9,8 @@ use std::path::{Path, PathBuf};
|
|||||||
pub mod prereqs;
|
pub mod prereqs;
|
||||||
pub mod repo;
|
pub mod repo;
|
||||||
|
|
||||||
|
type EnvInjector = Box<dyn Fn(&Path) -> Result<String>>;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct NotstrapConfig {
|
pub struct NotstrapConfig {
|
||||||
pub bootstrap: BootstrapSection,
|
pub bootstrap: BootstrapSection,
|
||||||
@@ -26,8 +28,8 @@ pub struct BootstrapSection {
|
|||||||
pub sops_file: String,
|
pub sops_file: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_bw_item() -> String { "age-key-dotfiles".to_string() }
|
pub(crate) fn default_bw_item() -> String { "age-key-dotfiles".to_string() }
|
||||||
pub fn default_sops_file() -> String { "secrets/bootstrap.sops.env".to_string() }
|
pub(crate) fn default_sops_file() -> String { "secrets/bootstrap.sops.env".to_string() }
|
||||||
|
|
||||||
pub struct BootstrapOptions {
|
pub struct BootstrapOptions {
|
||||||
pub config: PathBuf,
|
pub config: PathBuf,
|
||||||
@@ -37,7 +39,7 @@ pub struct BootstrapOptions {
|
|||||||
/// None = skip prereq check (tests). Some(f) = run f().
|
/// None = skip prereq check (tests). Some(f) = run f().
|
||||||
pub check_prereqs: Option<Box<dyn Fn() -> Result<()>>>,
|
pub check_prereqs: Option<Box<dyn Fn() -> Result<()>>>,
|
||||||
/// None = skip env injection (tests). Some(f) = decrypt sops at path and inject.
|
/// None = skip env injection (tests). Some(f) = decrypt sops at path and inject.
|
||||||
pub env_injector: Option<Box<dyn Fn(&Path) -> Result<String>>>,
|
pub env_injector: Option<EnvInjector>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(opts: BootstrapOptions) -> Result<Report> {
|
pub fn run(opts: BootstrapOptions) -> Result<Report> {
|
||||||
@@ -59,9 +61,11 @@ pub fn run(opts: BootstrapOptions) -> Result<Report> {
|
|||||||
.with_context(|| format!("cannot read {}", opts.config.display()))?;
|
.with_context(|| format!("cannot read {}", opts.config.display()))?;
|
||||||
let cfg: NotstrapConfig = toml::from_str(&config_content)?;
|
let cfg: NotstrapConfig = toml::from_str(&config_content)?;
|
||||||
|
|
||||||
let dotfiles_dir = opts.dotfiles.unwrap_or_else(|| {
|
let dotfiles_dir = match opts.dotfiles {
|
||||||
notcore::expand_tilde(&cfg.bootstrap.dotfiles_dir).unwrap()
|
Some(d) => d,
|
||||||
});
|
None => notcore::expand_tilde(&cfg.bootstrap.dotfiles_dir)
|
||||||
|
.with_context(|| format!("cannot expand dotfiles_dir: {}", cfg.bootstrap.dotfiles_dir))?,
|
||||||
|
};
|
||||||
|
|
||||||
// 3. Clone dotfiles if missing
|
// 3. Clone dotfiles if missing
|
||||||
match repo::clone_if_missing(&cfg.bootstrap.dotfiles_repo, &dotfiles_dir) {
|
match repo::clone_if_missing(&cfg.bootstrap.dotfiles_repo, &dotfiles_dir) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fn main() -> Result<()> {
|
|||||||
key_file,
|
key_file,
|
||||||
dotfiles,
|
dotfiles,
|
||||||
check_prereqs: Some(Box::new(prereqs::check_prerequisites)),
|
check_prereqs: Some(Box::new(prereqs::check_prerequisites)),
|
||||||
env_injector: Some(Box::new(|p| notsecrets::decrypt_sops(p))),
|
env_injector: Some(Box::new(notsecrets::decrypt_sops)),
|
||||||
};
|
};
|
||||||
let report = run(opts)?;
|
let report = run(opts)?;
|
||||||
report.print();
|
report.print();
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ pub fn clone_if_missing(url: &str, dest: &Path) -> Result<bool> {
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
let status = Command::new("git")
|
let status = Command::new("git")
|
||||||
.args(["clone", url, dest.to_str().unwrap()])
|
.arg("clone")
|
||||||
|
.arg(url)
|
||||||
|
.arg(dest)
|
||||||
.status()
|
.status()
|
||||||
.context("failed to run git clone")?;
|
.context("failed to run git clone")?;
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
|
|||||||
Reference in New Issue
Block a user