use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
mod aggregate;
mod analyze;
mod cache;
mod cli;
mod config;
mod extract;
mod render;
mod scan;
mod types;
pub use aggregate::*;
pub use analyze::*;
pub use cache::*;
pub use config::*;
pub use extract::*;
pub use render::*;
pub use scan::*;
pub use types::*;
#[derive(Parser)]
#[command(name = "atlas")]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[arg(short, long, global = true, default_value = ".")]
root: PathBuf,
#[arg(short, long, action = clap::ArgAction::Count, global = true)]
verbose: u8,
#[arg(short, long, global = true)]
quiet: bool,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Init,
Scan {
#[arg(long)]
dry_run: bool,
#[arg(long)]
json: bool,
},
Build {
#[arg(long)]
changed_only: bool,
#[arg(long)]
force: bool,
},
Doctor {
#[arg(long)]
json: bool,
},
Clean {
#[arg(long)]
all: bool,
},
Search {
query: String,
#[arg(long = "path")]
path_filters: Vec<String>,
#[arg(long = "type")]
type_filters: Vec<String>,
#[arg(long = "ext")]
ext_filters: Vec<String>,
#[arg(long)]
json: bool,
#[arg(long)]
explain: bool,
#[arg(long, default_value = "10")]
limit: usize,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
let log_level = match (cli.quiet, cli.verbose) {
(true, _) => LogLevel::Quiet,
(_, 0) => LogLevel::Normal,
(_, 1) => LogLevel::Verbose,
(_, _) => LogLevel::Debug,
};
match cli.command {
Commands::Init => cli::init::run(&cli.root, log_level),
Commands::Scan { dry_run, json } => cli::scan::run(&cli.root, dry_run, json, log_level),
Commands::Build {
changed_only,
force,
} => cli::build::run(&cli.root, changed_only, force, log_level),
Commands::Search {
query,
path_filters,
type_filters,
ext_filters,
json,
explain,
limit,
} => cli::search::run(
&cli.root,
&query,
&path_filters,
&type_filters,
&ext_filters,
json,
explain,
limit,
log_level,
),
Commands::Doctor { json } => cli::doctor::run(&cli.root, json, log_level),
Commands::Clean { all } => cli::clean::run(&cli.root, all, log_level),
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
Quiet,
Normal,
Verbose,
Debug,
}
impl LogLevel {
pub fn should_print(&self, level: LogLevel) -> bool {
(*self as u8) >= (level as u8)
}
}