use aiscope::cmd;
use aiscope::reason::ReasonMode;
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use std::process::ExitCode;
#[derive(Debug, Parser)]
#[command(name = "aiscope", version, about, long_about = None)]
struct Cli {
#[arg(default_value = ".")]
path: PathBuf,
#[arg(long, conflicts_with_all = ["json", "card", "diag"])]
text: bool,
#[arg(long, conflicts_with_all = ["text", "card", "diag"])]
json: bool,
#[arg(long, value_name = "PATH", conflicts_with_all = ["text", "json", "diag"])]
card: Option<PathBuf>,
#[arg(long, conflicts_with_all = ["text", "json", "card"])]
diag: bool,
#[arg(long, value_name = "PATTERN")]
grep: Option<String>,
#[arg(long)]
specific: bool,
#[arg(long)]
user: bool,
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
Check,
Watch,
}
fn main() -> Result<ExitCode> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "aiscope=info".into()),
)
.init();
let cli = Cli::parse();
let pipeline = cmd::PipelineOptions {
mode: if cli.specific {
ReasonMode::Specific
} else {
ReasonMode::Uniform
},
include_user: cli.user,
};
match cli.command {
Some(Command::Check) => cmd::check::run(&cli.path, pipeline),
Some(Command::Watch) => cmd::watch::run(&cli.path, pipeline).map(|_| ExitCode::SUCCESS),
None => cmd::scan::run(
&cli.path,
&cmd::scan::ScanOptions {
text: cli.text,
json: cli.json,
card: cli.card,
grep: cli.grep,
diag: cli.diag,
pipeline,
},
)
.map(|_| ExitCode::SUCCESS),
}
}