erpc_analysis/
args.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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,

    /// 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",
                "info-database",
                "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
  info-database                 Show database information

If no task is specified, runs the default analysis workflow."#
    }
}