Skip to content

Commit

Permalink
Feat: aderyn init (#722)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Roan <[email protected]>
  • Loading branch information
TilakMaddy and alexroan authored Sep 22, 2024
1 parent 2b68c8b commit 52b1d6e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
9 changes: 9 additions & 0 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use aderyn_driver::detector::{get_all_detectors_names, get_issue_detector_by_name, IssueSeverity};
use semver::Version;
use serde_json::Value;
use std::{fs::File, io::Write, path::PathBuf, str::FromStr};
use strum::IntoEnumIterator;

pub fn create_aderyn_toml_file_at(directory: String) {
let aderyn_toml_path = PathBuf::from_str(&directory).unwrap().join("aderyn.toml");
let mut file = File::create_new(aderyn_toml_path.clone()).expect("File already exists!");
file.write_all(include_bytes!("../templates/aderyn.toml"))
.expect("To write contents into aderyn.toml");
println!("Created aderyn.toml at {}", aderyn_toml_path.display());
}

mod panic;

pub fn initialize_niceties() {
Expand Down
18 changes: 16 additions & 2 deletions aderyn/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aderyn::{
aderyn_is_currently_running_newest_version, initialize_niceties, lsp::spin_up_language_server,
print_all_detectors_view, print_detail_view,
aderyn_is_currently_running_newest_version, create_aderyn_toml_file_at, initialize_niceties,
lsp::spin_up_language_server, print_all_detectors_view, print_detail_view,
};
use aderyn_driver::driver::{self, Args};

Expand All @@ -17,6 +17,10 @@ pub struct CommandLineArgs {
#[arg(default_value = ".")]
root: String,

/// Initialize aderyn.toml in [ROOT] which hosts all the configuration to override defaults
#[arg(long)]
init: bool,

/// Path to the source contracts. If not provided, the ROOT directory will be used.
///
/// For example, in a foundry repo:
Expand Down Expand Up @@ -101,6 +105,16 @@ fn main() {
return;
}

if cmd_args.root == "init" {
create_aderyn_toml_file_at(".".to_string());
return;
}

if cmd_args.init {
create_aderyn_toml_file_at(cmd_args.root);
return;
}

let mut args: Args = Args {
root: cmd_args.root,
output: cmd_args.output,
Expand Down
34 changes: 34 additions & 0 deletions aderyn/templates/aderyn.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Aderyn Configuration File
# This is a sample configuration for Aderyn

# The root directory of smart contracts
# root = "."

# By default, aderyn will try to extract the following values based on the framework that is being used.
# However, if you want to be explicit consider mentioning them.

# The source directory containing the Solidity contracts.
# This is often "contracts/" or "src/"
# src = "src/"

# Contract files to include in the analysis.
# This is a list of strings representing the file paths of the contracts to include.
# It can be a partial match like "/interfaces/", which will include all files with "/interfaces/" in the file path.
# Or it can be a full match like "Counter.sol", which will include only the file with the exact file.
# If not specified, all contract files in the source directory will be included.
# Example:
# include = ["Counter.sol"]
# include = []

# Contract files to exclude from the analysis.
# This is a list of strings representing the file paths of the contracts to exclude.
# It can be a partial match like "/interfaces/", which will exclude all files with "/interfaces/" in the file path.
# Or it can be a full match like "Counter.sol", which will exclude only the file with the exact file.
# If not specified, no contract files will be excluded.
# Example:
# exclude = ["/interfaces/"]
# exclude = []

## Remappings used for compiling the contracts.
# Example:
# remappings = ["@oz/contracts=lib/openzeppelin-contracts/contracts"]

0 comments on commit 52b1d6e

Please sign in to comment.