Skip to content

Commit

Permalink
node_prune.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Oct 19, 2024
1 parent 40ad3a5 commit 4853791
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/apps/node_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::install::{self, Method};
use crate::platform::{Cpu, Os, Platform};
use crate::prelude::*;
use crate::subshell::Executable;
use crate::{regexp, Log};
use crate::Log;
use const_format::formatcp;

pub struct NodePrune {}
Expand Down Expand Up @@ -39,10 +39,7 @@ impl App for NodePrune {
if !identify(&output) {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Ok(AnalyzeResult::IdentifiedButUnknownVersion)
}
}

Expand All @@ -67,17 +64,12 @@ impl install::CompileGoSource for NodePrune {
}
}

fn extract_version(output: &str) -> Result<&str> {
regexp::first_capture(output, r"v(\d+\.\d+\.\d+) \(go")
}

fn identify(output: &str) -> bool {
output.contains("display diffs instead of rewriting files")
output.contains("Glob of files that should not be pruned")
}

#[cfg(test)]
mod tests {
use crate::apps::UserError;

mod artifact_url {
use crate::config::Version;
Expand All @@ -96,10 +88,4 @@ mod tests {
assert_eq!(have, want);
}
}

#[test]
fn extract_version() {
assert_eq!(super::extract_version("v0.6.0 (go1.21.6)"), Ok("0.6.0"));
assert_eq!(super::extract_version("other"), Err(UserError::RegexDoesntMatch));
}
}

0 comments on commit 4853791

Please sign in to comment.