pub mod args;
pub mod completions;
pub mod config;
pub mod dangerous_path;
pub mod db;
pub mod debug;
pub mod decisions;
pub mod error;
pub mod format;
pub mod init;
pub mod instructions;
pub mod report;
pub mod review;
pub mod scan;
pub mod serve;
pub mod status;
pub mod tui;
pub mod uninstall;
pub mod update;
pub mod version_cache;
pub use args::{Cli, Command};
pub use db::{find_git_root, get_current_branch};
pub use error::CliError;
pub use format::Verbosity;
use clap::Parser;
use tracing_subscriber::EnvFilter;
pub fn run() -> Result<(), CliError> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_env("SESHAT_LOG").unwrap_or_else(|_| EnvFilter::new("warn")),
)
.with_target(false)
.with_writer(std::io::stderr)
.init();
if !matches!(
cli.command,
Command::Update { .. } | Command::Completions { .. }
) {
update::cleanup_stale_old_binary();
update::check_and_print_update_notice();
}
match cli.command {
Command::Scan {
path,
verbose,
quiet,
exclude_submodules,
} => scan::run_scan(&path, verbose, quiet, exclude_submodules),
Command::Serve {
repo,
host,
port,
call_log,
} => serve::run_serve(repo.as_deref(), host, port, call_log),
Command::Status { verbose } => status::run_status(verbose),
Command::Review { no_sync } => review::run_review(None, no_sync),
Command::Decisions { command } => decisions::run_decisions(command),
Command::DebugSnippets { path } => {
let resolved = db::resolve_project(path.as_deref(), "debug")?;
let branch = db::detect_branch(&resolved.project_root);
debug::run_debug(&resolved.db_path, &branch)
}
Command::Init {
client,
project,
global,
dry_run,
skip_instructions,
} => {
let scope = if project {
init::ScopeRequest::Project
} else if global {
init::ScopeRequest::Global
} else {
init::ScopeRequest::Auto
};
init::run_init(client.as_deref(), scope, dry_run, skip_instructions)
}
Command::Uninstall {
client,
project,
global,
dry_run,
} => {
let scope = if project {
uninstall::ScopeRequest::Project
} else if global {
uninstall::ScopeRequest::Global
} else {
uninstall::ScopeRequest::Auto
};
uninstall::run_uninstall(client.as_deref(), scope, dry_run)
}
Command::Update { check } => update::run_update(check),
Command::Completions { shell } => completions::run_completions(shell),
}
}