2025-06-24 20:27:06 +02:00
|
|
|
pub mod clean;
|
2026-02-25 04:02:11 -05:00
|
|
|
pub mod config;
|
2025-06-16 16:46:22 +02:00
|
|
|
pub mod index;
|
|
|
|
|
pub mod list;
|
2025-06-24 20:27:06 +02:00
|
|
|
pub mod scan;
|
2025-06-16 16:46:22 +02:00
|
|
|
|
|
|
|
|
use crate::cli::Commands;
|
2025-06-23 20:59:49 +02:00
|
|
|
use crate::errors::NyxResult;
|
2025-06-23 16:51:39 +02:00
|
|
|
use crate::patterns::Severity;
|
2025-06-28 17:36:14 +02:00
|
|
|
use crate::utils::config::{AnalysisMode, Config};
|
2025-06-24 20:27:06 +02:00
|
|
|
use std::path::Path;
|
2025-06-16 16:46:22 +02:00
|
|
|
|
|
|
|
|
pub fn handle_command(
|
|
|
|
|
command: Commands,
|
|
|
|
|
database_dir: &Path,
|
2026-02-25 04:02:11 -05:00
|
|
|
config_dir: &Path,
|
2025-06-24 20:27:06 +02:00
|
|
|
config: &mut Config,
|
2025-06-23 20:59:49 +02:00
|
|
|
) -> NyxResult<()> {
|
2025-06-16 16:46:22 +02:00
|
|
|
match command {
|
2025-06-24 20:27:06 +02:00
|
|
|
Commands::Scan {
|
|
|
|
|
path,
|
|
|
|
|
no_index,
|
|
|
|
|
rebuild_index,
|
|
|
|
|
format,
|
|
|
|
|
high_only,
|
2025-06-28 17:36:14 +02:00
|
|
|
ast_only,
|
|
|
|
|
cfg_only,
|
|
|
|
|
all_targets,
|
2026-02-25 04:02:11 -05:00
|
|
|
include_nonprod,
|
2025-06-24 20:27:06 +02:00
|
|
|
} => {
|
|
|
|
|
if high_only {
|
|
|
|
|
config.scanner.min_severity = Severity::High
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-28 17:36:14 +02:00
|
|
|
if ast_only {
|
|
|
|
|
config.scanner.mode = AnalysisMode::Ast
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if cfg_only {
|
|
|
|
|
config.scanner.mode = AnalysisMode::Taint
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if all_targets {
|
|
|
|
|
config.scanner.mode = AnalysisMode::Full
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-25 04:02:11 -05:00
|
|
|
if include_nonprod {
|
|
|
|
|
config.scanner.include_nonprod = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
scan::handle(&path, no_index, rebuild_index, format, database_dir, config)?;
|
|
|
|
|
}
|
|
|
|
|
Commands::Index { action } => {
|
|
|
|
|
index::handle(action, database_dir, config)?;
|
|
|
|
|
}
|
|
|
|
|
Commands::List { verbose } => {
|
|
|
|
|
list::handle(verbose, database_dir)?;
|
|
|
|
|
}
|
|
|
|
|
Commands::Clean { project, all } => {
|
|
|
|
|
clean::handle(project, all, database_dir)?;
|
|
|
|
|
}
|
|
|
|
|
Commands::Config { action } => {
|
|
|
|
|
use crate::cli::ConfigAction;
|
|
|
|
|
match action {
|
|
|
|
|
ConfigAction::Show => self::config::show(config)?,
|
|
|
|
|
ConfigAction::Path => self::config::path(config_dir)?,
|
|
|
|
|
ConfigAction::AddRule {
|
|
|
|
|
lang,
|
|
|
|
|
matcher,
|
|
|
|
|
kind,
|
|
|
|
|
cap,
|
|
|
|
|
} => self::config::add_rule(config_dir, &lang, &matcher, &kind, &cap)?,
|
|
|
|
|
ConfigAction::AddTerminator { lang, name } => {
|
|
|
|
|
self::config::add_terminator(config_dir, &lang, &name)?
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-16 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-25 04:02:11 -05:00
|
|
|
Ok(())
|
2025-06-24 20:27:06 +02:00
|
|
|
}
|