use anyhow::Result;
use clap::{Parser, Subcommand};
use tracing::info;
mod api;
mod cache;
mod cli;
mod index;
mod parser;
use cli::commands;
#[derive(Parser)]
#[command(
name = "woofind",
about = "🔍 Blazing-fast Go import discovery",
version,
author
)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, global = true)]
verbose: bool,
}
#[derive(Subcommand)]
enum Commands {
Index {
#[arg(default_value = ".")]
path: String,
#[arg(short, long)]
watch: bool,
},
Query {
symbol: String,
#[arg(short, long, default_value = "10")]
limit: usize,
#[arg(short, long)]
fuzzy: bool,
},
Serve {
#[arg(short, long, default_value = "127.0.0.1:7373")]
bind: String,
},
Stats,
Clear,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let subscriber = tracing_subscriber::fmt()
.with_env_filter(
std::env::var("RUST_LOG")
.unwrap_or_else(|_| if cli.verbose { "debug" } else { "info" }.into()),
)
.finish();
tracing::subscriber::set_global_default(subscriber)?;
info!("🐕 woofind starting...");
match cli.command {
Commands::Index { path, watch } => {
commands::index::run(&path, watch).await?;
}
Commands::Query {
symbol,
limit,
fuzzy,
} => {
commands::query::run(&symbol, limit, fuzzy).await?;
}
Commands::Serve { bind } => {
commands::serve::run(&bind).await?;
}
Commands::Stats => {
commands::stats::run().await?;
}
Commands::Clear => {
commands::clear::run().await?;
}
}
Ok(())
}