Skip to content

Commit

Permalink
Cleaner driver (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan authored May 7, 2024
1 parent 0fdb644 commit a33e7b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 67 deletions.
27 changes: 2 additions & 25 deletions aderyn_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,13 @@ use std::io::{self};
use std::path::{Path, PathBuf};

use crate::context::workspace_context::WorkspaceContext;
use crate::detect::detector::{get_all_issue_detectors, IssueSeverity};
use crate::detect::detector::IssueSeverity;

use crate::report::printer::ReportPrinter;
use crate::report::reporter::Report;
use crate::report::Issue;

pub fn run_with_printer<T>(
context: &WorkspaceContext,
output_file_path: String,
reporter: T,
root_rel_path: PathBuf,
no_snippets: bool,
stdout: bool,
) -> Result<(), Box<dyn Error>>
where
T: ReportPrinter<()>,
{
let detectors = get_all_issue_detectors();
run_with_printer_and_given_detectors(
context,
output_file_path,
reporter,
root_rel_path,
no_snippets,
stdout,
detectors,
)
}

pub fn run_with_printer_and_given_detectors<T>(
pub fn run<T>(
context: &WorkspaceContext,
output_file_path: String,
reporter: T,
Expand Down
47 changes: 5 additions & 42 deletions aderyn_driver/src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{process_foundry, process_hardhat, virtual_foundry};
use aderyn_core::{
context::workspace_context::WorkspaceContext,
detect::detector::IssueDetector,
detect::detector::{get_all_issue_detectors, IssueDetector},
fscloc,
report::{json_printer::JsonPrinter, markdown_printer::MarkdownReportPrinter},
run_with_printer, run_with_printer_and_given_detectors,
run,
};
use std::{fs::read_dir, path::PathBuf};

Expand All @@ -26,44 +26,7 @@ enum Framework {
}

pub fn drive(args: Args) {
let output = args.output.clone();
let cx_wrapper = make_context(&args);
let root_rel_path = PathBuf::from(&args.root);
let context = &cx_wrapper.context;

if args.output.ends_with(".json") {
// Load the workspace context into the run function, which runs the detectors
run_with_printer(
context,
output,
JsonPrinter,
root_rel_path,
args.no_snippets,
args.stdout,
)
.unwrap_or_else(|err| {
// Exit with a non-zero exit code
eprintln!("Error running aderyn");
eprintln!("{:?}", err);
std::process::exit(1);
});
} else {
// Load the workspace context into the run function, which runs the detectors
run_with_printer(
context,
output,
MarkdownReportPrinter,
root_rel_path,
args.no_snippets,
args.stdout,
)
.unwrap_or_else(|err| {
// Exit with a non-zero exit code
eprintln!("Error running aderyn");
eprintln!("{:?}", err);
std::process::exit(1);
});
}
drive_with(args, get_all_issue_detectors());
}

pub fn drive_with(args: Args, detectors: Vec<Box<dyn IssueDetector>>) {
Expand All @@ -74,7 +37,7 @@ pub fn drive_with(args: Args, detectors: Vec<Box<dyn IssueDetector>>) {

if args.output.ends_with(".json") {
// Load the workspace context into the run function, which runs the detectors
run_with_printer_and_given_detectors(
run(
context,
output,
JsonPrinter,
Expand All @@ -91,7 +54,7 @@ pub fn drive_with(args: Args, detectors: Vec<Box<dyn IssueDetector>>) {
});
} else {
// Load the workspace context into the run function, which runs the detectors
run_with_printer_and_given_detectors(
run(
context,
output,
MarkdownReportPrinter,
Expand Down

0 comments on commit a33e7b8

Please sign in to comment.