Skip to content

Commit

Permalink
Combine the two execute methods (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo authored Feb 17, 2025
1 parent a52bac5 commit 6ed9ddf
Show file tree
Hide file tree
Showing 30 changed files with 42 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/applications/actionlint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ impl AppDefinition for ActionLint {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("actionlint is a linter for GitHub Actions workflow files") {
return Ok(AnalyzeResult::NotIdentified { output });
}
let output = executable.run_output("--version", log)?;
let output = executable.run_output(&["--version"], log)?;
match extract_version(&output) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::NotIdentified { output }),
Expand Down
2 changes: 1 addition & 1 deletion src/applications/alphavet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl AppDefinition for Alphavet {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Checks that functions are ordered alphabetically within packages") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/deadcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AppDefinition for Deadcode {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("The deadcode command reports unreachable functions in Go programs") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl AppDefinition for Depth {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("resolves dependencies of internal (stdlib) packages.") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/dprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl AppDefinition for Dprint {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Auto-formats source code based on the specified plugins") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/exhaustruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl AppDefinition for Exhaustruct {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("exhaustruct: Checks if all structure fields are initialized") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/gh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ impl AppDefinition for Gh {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Work seamlessly with GitHub from the command line") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/ghokin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl AppDefinition for Ghokin {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Clean and/or apply transformation on gherkin files") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ impl AppDefinition for Go {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
if let Ok(version) = extract_version(&executable.run_output("version", log)?) {
if let Ok(version) = extract_version(&executable.run_output(&["version"], log)?) {
return Ok(AnalyzeResult::IdentifiedWithVersion(version.into()));
}
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if output.contains("Go is a tool for managing Go source code") {
Ok(AnalyzeResult::IdentifiedButUnknownVersion)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/applications/goda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl AppDefinition for Goda {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("help", log)?;
let output = executable.run_output(&["help"], log)?;
if !output.contains("Print dependency graph") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/gofmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl AppDefinition for Gofmt {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("report all errors (not just the first 10 on different lines)") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/gofumpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl AppDefinition for Gofumpt {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("display diffs instead of rewriting files") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/golangci_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl AppDefinition for GolangCiLint {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/goreleaser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl AppDefinition for Goreleaser {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-v", log)?;
let output = executable.run_output(&["-v"], log)?;
if !output.contains("https://goreleaser.com") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/govulnchec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AppDefinition for Govulncheck {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Govulncheck reports known vulnerabilities in dependencies") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/ireturn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl AppDefinition for Ireturn {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("ireturn: Accept Interfaces, Return Concrete Types") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/mdbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ impl AppDefinition for MdBook {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Creates a book from markdown files") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("-V", log)?) {
match extract_version(&executable.run_output(&["-V"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/mdbook_linkcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ impl AppDefinition for MdBookLinkCheck {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("mdbook-linkcheck") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("-V", log)?) {
match extract_version(&executable.run_output(&["-V"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
1 change: 0 additions & 1 deletion src/applications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl Apps {
}

/// provides the app with the given name
/// TODO: return the actual Box<dyn App> instead of a reference here
pub(crate) fn lookup<AS: AsRef<str>>(&self, name: AS) -> Result<&dyn AppDefinition> {
for app in &self.0 {
if app.name() == name.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion src/applications/node_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl AppDefinition for NodePrune {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Glob of files that should not be pruned") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/nodejs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ impl AppDefinition for NodeJS {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Documentation can be found at https://nodejs.org") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AppDefinition for Npm {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output_args(&["help", "npm"], log)?;
let output = executable.run_output(&["help", "npm"], log)?;
if !output.contains("javascript package manager") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/npx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AppDefinition for Npx {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Run a command from a local or remote npm package") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/ripgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AppDefinition for RipGrep {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("ripgrep") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/scc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl AppDefinition for Scc {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Count lines of code in a directory with complexity estimation") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/shellcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl AppDefinition for ShellCheck {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("--version", log)?;
let output = executable.run_output(&["--version"], log)?;
if !output.contains("ShellCheck - shell script analysis tool") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/shfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl AppDefinition for Shfmt {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("shfmt formats shell programs") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/staticcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl AppDefinition for StaticCheck {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Usage: staticcheck [flags] [packages]") {
return Ok(AnalyzeResult::NotIdentified { output });
}
Expand Down
4 changes: 2 additions & 2 deletions src/applications/tikibase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl AppDefinition for Tikibase {
}

fn analyze_executable(&self, executable: &ExecutablePath, log: Log) -> Result<AnalyzeResult> {
let output = executable.run_output("-h", log)?;
let output = executable.run_output(&["-h"], log)?;
if !output.contains("Linter for Markdown-based knowledge databases") {
return Ok(AnalyzeResult::NotIdentified { output });
}
match extract_version(&executable.run_output("--version", log)?) {
match extract_version(&executable.run_output(&["--version"], log)?) {
Ok(version) => Ok(AnalyzeResult::IdentifiedWithVersion(version.into())),
Err(_) => Ok(AnalyzeResult::IdentifiedButUnknownVersion),
}
Expand Down
32 changes: 3 additions & 29 deletions src/run/executable_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,13 @@ impl ExecutablePath {
}

/// runs this executable with the given args and returns the output it produced
// TODO: move this into ExecutableCall
pub(crate) fn run_output(&self, arg: &str, log: Log) -> Result<String> {
let mut cmd = Command::new(self);
cmd.arg(arg);
#[allow(clippy::unwrap_used)] // there is always a parent here since this is a location inside the yard
add_paths(&mut cmd, &[self.0.parent().unwrap()]);
log(Event::AnalyzeExecutableBegin {
cmd: &self.as_str(),
args: &[arg],
});
let output = match cmd.output() {
Ok(output) => output,
Err(err) => {
log(Event::AnalyzeExecutableError { err: err.to_string() });
return Err(UserError::ExecutableCannotExecute {
executable: self.clone(),
err: err.to_string(),
});
}
};
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let output = format!("{stdout}{stderr}");
Ok(output)
}

/// runs this executable with the given args and returns the output it produced
// TODO: move this into ExecutableCall
pub(crate) fn run_output_args(&self, args: &[&str], log: Log) -> Result<String> {
// TODO: use ExecutableCall internally?
pub(crate) fn run_output(&self, args: &[&str], log: Log) -> Result<String> {
let mut cmd = Command::new(self);
cmd.args(args);
#[allow(clippy::unwrap_used)] // there is always a parent here since this is a location inside the yard
add_paths(&mut cmd, &[self.0.parent().unwrap()]);
log(Event::AnalyzeExecutableBegin { cmd: &self.as_str(), args });
let output = match cmd.output() {
Ok(output) => output,
Err(err) => {
Expand Down

0 comments on commit 6ed9ddf

Please sign in to comment.