Skip to content

Commit

Permalink
remove --init
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Oct 12, 2024
1 parent a886f67 commit 25a152a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
20 changes: 3 additions & 17 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use aderyn_driver::detector::{get_all_detectors_names, get_issue_detector_by_name, IssueSeverity};
use semver::Version;
use serde_json::Value;
use std::fs;
use std::{fs::File, io::Write, path::PathBuf, str::FromStr};
use strum::IntoEnumIterator;

pub mod lsp;
mod panic;

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!");
Expand All @@ -13,27 +15,11 @@ pub fn create_aderyn_toml_file_at(directory: String) {
println!("Created aderyn.toml at {}", aderyn_toml_path.display());
}

pub fn validate_path_for_file_creation(path: &PathBuf) -> Result<&PathBuf, String> {
if !path.exists() {
return Err(format!("The directory '{}' does not exist.", path.display()));
}

if !fs::metadata(path).map(|meta| meta.is_dir()).unwrap_or(false) {
return Err(format!("The path '{}' is not a directory.", path.display()));
}

Ok(path)
}

mod panic;

pub fn initialize_niceties() {
// Crash with a nice message on panic
panic::add_handler()
}

pub mod lsp;

pub fn print_detail_view(detector_name: &str) {
let all_detector_names = get_all_detectors_names();
if !all_detector_names.contains(&detector_name.to_string()) {
Expand Down
25 changes: 10 additions & 15 deletions aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::PathBuf;
use aderyn::{
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,
validate_path_for_file_creation,
};
use aderyn_driver::driver::{self, Args};

Expand All @@ -12,18 +11,14 @@ use clap::{ArgGroup, Parser, Subcommand};
#[command(author, version, about, long_about = None)]
#[command(group(ArgGroup::new("stdout_dependent").requires("stdout")))]
pub struct CommandLineArgs {
/// Print every detector available
/// Commands to initialize a config file for aderyn [BETA] and other utils
#[clap(subcommand)]
subcommand: Option<Command>,

/// Foundry or Hardhat project root directory (or path to single solidity file)
#[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 @@ -115,10 +110,15 @@ fn main() {
let mut target_dir = PathBuf::from(&cmd_args.root);
target_dir.push(optional_path);

validate_path_for_file_creation(&target_dir)
.expect("Error - Cannot create aderyn.toml")
.to_string_lossy()
.into_owned()
let can_initialize = target_dir.exists()
&& std::fs::metadata(&target_dir).is_ok_and(|p| p.is_dir());

if !can_initialize {
eprintln!("Failed to initialize aderyn.toml in non-existent directory");
std::process::exit(1);
}

target_dir.to_string_lossy().to_string()
}
None => cmd_args.root,
};
Expand All @@ -131,11 +131,6 @@ fn main() {
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

0 comments on commit 25a152a

Please sign in to comment.