Skip to content

Commit a33e7b8

Browse files
authored
Cleaner driver (#403)
1 parent 0fdb644 commit a33e7b8

File tree

2 files changed

+7
-67
lines changed

2 files changed

+7
-67
lines changed

aderyn_core/src/lib.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,13 @@ use std::io::{self};
1515
use std::path::{Path, PathBuf};
1616

1717
use crate::context::workspace_context::WorkspaceContext;
18-
use crate::detect::detector::{get_all_issue_detectors, IssueSeverity};
18+
use crate::detect::detector::IssueSeverity;
1919

2020
use crate::report::printer::ReportPrinter;
2121
use crate::report::reporter::Report;
2222
use crate::report::Issue;
2323

24-
pub fn run_with_printer<T>(
25-
context: &WorkspaceContext,
26-
output_file_path: String,
27-
reporter: T,
28-
root_rel_path: PathBuf,
29-
no_snippets: bool,
30-
stdout: bool,
31-
) -> Result<(), Box<dyn Error>>
32-
where
33-
T: ReportPrinter<()>,
34-
{
35-
let detectors = get_all_issue_detectors();
36-
run_with_printer_and_given_detectors(
37-
context,
38-
output_file_path,
39-
reporter,
40-
root_rel_path,
41-
no_snippets,
42-
stdout,
43-
detectors,
44-
)
45-
}
46-
47-
pub fn run_with_printer_and_given_detectors<T>(
24+
pub fn run<T>(
4825
context: &WorkspaceContext,
4926
output_file_path: String,
5027
reporter: T,

aderyn_driver/src/driver.rs

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::{process_foundry, process_hardhat, virtual_foundry};
22
use aderyn_core::{
33
context::workspace_context::WorkspaceContext,
4-
detect::detector::IssueDetector,
4+
detect::detector::{get_all_issue_detectors, IssueDetector},
55
fscloc,
66
report::{json_printer::JsonPrinter, markdown_printer::MarkdownReportPrinter},
7-
run_with_printer, run_with_printer_and_given_detectors,
7+
run,
88
};
99
use std::{fs::read_dir, path::PathBuf};
1010

@@ -26,44 +26,7 @@ enum Framework {
2626
}
2727

2828
pub fn drive(args: Args) {
29-
let output = args.output.clone();
30-
let cx_wrapper = make_context(&args);
31-
let root_rel_path = PathBuf::from(&args.root);
32-
let context = &cx_wrapper.context;
33-
34-
if args.output.ends_with(".json") {
35-
// Load the workspace context into the run function, which runs the detectors
36-
run_with_printer(
37-
context,
38-
output,
39-
JsonPrinter,
40-
root_rel_path,
41-
args.no_snippets,
42-
args.stdout,
43-
)
44-
.unwrap_or_else(|err| {
45-
// Exit with a non-zero exit code
46-
eprintln!("Error running aderyn");
47-
eprintln!("{:?}", err);
48-
std::process::exit(1);
49-
});
50-
} else {
51-
// Load the workspace context into the run function, which runs the detectors
52-
run_with_printer(
53-
context,
54-
output,
55-
MarkdownReportPrinter,
56-
root_rel_path,
57-
args.no_snippets,
58-
args.stdout,
59-
)
60-
.unwrap_or_else(|err| {
61-
// Exit with a non-zero exit code
62-
eprintln!("Error running aderyn");
63-
eprintln!("{:?}", err);
64-
std::process::exit(1);
65-
});
66-
}
29+
drive_with(args, get_all_issue_detectors());
6730
}
6831

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

7538
if args.output.ends_with(".json") {
7639
// Load the workspace context into the run function, which runs the detectors
77-
run_with_printer_and_given_detectors(
40+
run(
7841
context,
7942
output,
8043
JsonPrinter,
@@ -91,7 +54,7 @@ pub fn drive_with(args: Args, detectors: Vec<Box<dyn IssueDetector>>) {
9154
});
9255
} else {
9356
// Load the workspace context into the run function, which runs the detectors
94-
run_with_printer_and_given_detectors(
57+
run(
9558
context,
9659
output,
9760
MarkdownReportPrinter,

0 commit comments

Comments
 (0)