use clap::Parser;
#[derive(Parser)]
#[command(
name = "analyze",
override_usage = "analyze [-f SYMBOL] [-d DEPTH] [-m DEPTH] [--ast-recursion-limit N] <PATH>"
)]
struct Args {
path: String,
#[arg(short, long)]
focus: Option<String>,
#[arg(short = 'd', long, default_value_t = 2)]
follow_depth: u32,
#[arg(short = 'm', long, default_value_t = 3)]
max_depth: u32,
#[arg(long)]
ast_recursion_limit: Option<usize>,
}
fn main() {
let args = match Args::try_parse() {
Ok(args) => args,
Err(e) => {
if e.kind() == clap::error::ErrorKind::DisplayHelp
|| e.kind() == clap::error::ErrorKind::DisplayVersion
{
print!("{e}");
std::process::exit(0);
}
eprintln!(
"Usage: analyze [-f SYMBOL] [-d DEPTH] [-m DEPTH] [--ast-recursion-limit N] <PATH>"
);
eprintln!("Try 'analyze --help' for more information.");
std::process::exit(1);
}
};
let cwd = std::env::current_dir()
.expect("Failed to get current directory")
.to_string_lossy()
.to_string();
let result = code_analyze::analyze(
&args.path,
args.focus.as_deref(),
args.follow_depth,
args.max_depth,
args.ast_recursion_limit,
&cwd,
);
print!("{}", result);
}