use anyhow;
use clap::Parser;
#[derive(Parser)]
pub struct Args {
#[arg(short, long, default_value = "config/primary/Config.toml")]
pub config: String,
#[arg(long, default_value = "erpc-analysis/src/log_config.yml")]
pub log_config: String,
#[arg(short, long)]
pub task: Option<String>,
#[arg(long)]
pub force: bool,
}
impl Args {
pub fn setup(&self) -> anyhow::Result<()> {
self.validate_arguments()?;
Ok(())
}
pub fn validate_arguments(&self) -> anyhow::Result<()> {
use std::path::Path;
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
));
}
}
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(())
}
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."#
}
}