use anyhow;
use clap::Parser;
/// erpc-analysis: A tool for analyzing Tor network data from eRPC.
#[derive(Parser)]
pub struct Args {
/// Path to the configuration TOML file.
#[arg(short, long, default_value = "config/primary/Config.toml")]
pub config: String,
/// Path to the log4rs YAML configuration file.
#[arg(long, default_value = "erpc-analysis/src/log_config.yml")]
pub log_config: String,
/// Path to the analysis-specific configuration TOML file.
#[arg(long, default_value = "erpc-analysis/analysis_config.toml")]
pub analysis_config: String,
/// Specific analysis task to run. If not specified, runs
/// default analysis workflow.
#[arg(short, long)]
pub task: Option<String>,
/// Force recreation of graph projection if it already exists.
#[arg(long)]
pub force: bool,
}
impl Args {
/// Setup method that handles validation
pub fn setup(&self) -> anyhow::Result<()> {
self.validate_arguments()?;
Ok(())
}
pub fn validate_arguments(&self) -> anyhow::Result<()> {
use std::path::Path;
// Check for file existence
for (file, description) in
[(&self.config, "Config"), (&self.log_config, "Log Config")]
{
if !Path::new(file).exists() {
return Err(anyhow::anyhow!(
"Error: {} file '{}' is missing",
description,
file
));
}
}
// Validate task if specified
if let Some(ref task) = self.task {
let valid_tasks = [
"projection-create",
"projection-delete",
"projection-exists",
"metrics-basic",
"metrics-degrees",
"metrics-distribution",
"components-analysis",
"community-louvain-consensus",
"community-lpa",
"partition-classify-geography",
"partition-classify-asn",
"partition-classify-family",
"partition-classify-all",
"centrality-betweenness",
"centrality-closeness",
"centrality-combined",
"path-connectivity",
"advanced-path-analysis",
"info-database",
"web-server",
"help",
];
if !valid_tasks.contains(&task.as_str()) {
return Err(anyhow::anyhow!(
"Error: Invalid task '{}'. Valid tasks are: {}\n\nFor \
detailed help, use: --task help",
task,
valid_tasks.join(", ")
));
}
}
Ok(())
}
/// Get help text for available tasks
pub fn task_help() -> &'static str {
r#"Available tasks:
projection-create Create a new graph projection
projection-delete Delete an existing graph projection
projection-exists Check if a projection exists
metrics-basic Calculate basic graph metrics
metrics-degrees Calculate node degree metrics
metrics-distribution Show degree distribution
components-analysis Analyze network connectivity components
community-louvain-consensus Run Louvain multiple times to analyze stability (configurable runs)
community-lpa Analyze communities using Label Propagation algorithm
partition-classify-geography Classify partitions by geographic location (country)
partition-classify-asn Classify partitions by Autonomous System Number (ASN)
partition-classify-family Classify partitions by relay family relationships
partition-classify-all Run all partition classification analyses
centrality-betweenness Calculate betweenness centrality for network nodes
centrality-closeness Calculate closeness centrality for network nodes
centrality-combined Calculate both betweenness and closeness centrality
path-connectivity Analyze internal connectivity within communities detected by Louvain algorithm
advanced-path-analysis Comprehensive path analysis using Louvain community detection and ASN-based classification
info-database Show database information
web-server Start the web server for visualization API
If no task is specified, runs the default analysis workflow."#
}
}