From 748a0d863481f5694e8aa757eefec86da838f76f Mon Sep 17 00:00:00 2001 From: Joseph O'Brien <98370624+89jobrien@users.noreply.github.com> Date: Wed, 1 Apr 2026 05:00:26 -0400 Subject: [PATCH] fix(notstrap): fix clippy warning and unwrap panics in lib extraction --- crates/notstrap/src/lib.rs | 16 ++++++++++------ crates/notstrap/src/main.rs | 2 +- crates/notstrap/src/repo.rs | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/notstrap/src/lib.rs b/crates/notstrap/src/lib.rs index 5dfc447..7ee7116 100644 --- a/crates/notstrap/src/lib.rs +++ b/crates/notstrap/src/lib.rs @@ -9,6 +9,8 @@ use std::path::{Path, PathBuf}; pub mod prereqs; pub mod repo; +type EnvInjector = Box Result>; + #[derive(Deserialize)] pub struct NotstrapConfig { pub bootstrap: BootstrapSection, @@ -26,8 +28,8 @@ pub struct BootstrapSection { pub sops_file: String, } -pub 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_bw_item() -> String { "age-key-dotfiles".to_string() } +pub(crate) fn default_sops_file() -> String { "secrets/bootstrap.sops.env".to_string() } pub struct BootstrapOptions { pub config: PathBuf, @@ -37,7 +39,7 @@ pub struct BootstrapOptions { /// None = skip prereq check (tests). Some(f) = run f(). pub check_prereqs: Option Result<()>>>, /// None = skip env injection (tests). Some(f) = decrypt sops at path and inject. - pub env_injector: Option Result>>, + pub env_injector: Option, } pub fn run(opts: BootstrapOptions) -> Result { @@ -59,9 +61,11 @@ pub fn run(opts: BootstrapOptions) -> Result { .with_context(|| format!("cannot read {}", opts.config.display()))?; let cfg: NotstrapConfig = toml::from_str(&config_content)?; - let dotfiles_dir = opts.dotfiles.unwrap_or_else(|| { - notcore::expand_tilde(&cfg.bootstrap.dotfiles_dir).unwrap() - }); + let dotfiles_dir = match opts.dotfiles { + 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 match repo::clone_if_missing(&cfg.bootstrap.dotfiles_repo, &dotfiles_dir) { diff --git a/crates/notstrap/src/main.rs b/crates/notstrap/src/main.rs index dc3164c..63a5abb 100644 --- a/crates/notstrap/src/main.rs +++ b/crates/notstrap/src/main.rs @@ -40,7 +40,7 @@ fn main() -> Result<()> { key_file, dotfiles, 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)?; report.print(); diff --git a/crates/notstrap/src/repo.rs b/crates/notstrap/src/repo.rs index 0ddc667..c7a23ba 100644 --- a/crates/notstrap/src/repo.rs +++ b/crates/notstrap/src/repo.rs @@ -7,7 +7,9 @@ pub fn clone_if_missing(url: &str, dest: &Path) -> Result { return Ok(false); } let status = Command::new("git") - .args(["clone", url, dest.to_str().unwrap()]) + .arg("clone") + .arg(url) + .arg(dest) .status() .context("failed to run git clone")?; if !status.success() {