use clap::Parser;
#[derive(Parser, Debug)]
#[command(name = "pacsea")]
#[command(version)]
#[command(about = "A fast, friendly TUI for browsing and installing Arch and AUR packages", long_about = None)]
#[allow(clippy::struct_excessive_bools)]
pub struct Args {
#[arg(long)]
pub dry_run: bool,
#[arg(long, default_value = "info")]
pub log_level: String,
#[arg(short, long)]
pub verbose: bool,
#[arg(long)]
pub no_color: bool,
#[arg(long)]
pub config_dir: Option<String>,
#[arg(short, long)]
pub search: Option<String>,
#[arg(short, long, num_args = 1..)]
pub install: Vec<String>,
#[arg(short = 'I')]
pub install_from_file: Option<String>,
#[arg(short = 'r', long, num_args = 1..)]
pub remove: Vec<String>,
#[arg(short = 'R')]
pub remove_from_file: Option<String>,
#[arg(short = 'u', long)]
pub update: bool,
#[arg(short = 'n', long)]
pub news: bool,
#[arg(long)]
pub unread: bool,
#[arg(long)]
pub read: bool,
#[arg(long, short = 'a')]
pub all_news: bool,
#[arg(long)]
pub clear_cache: bool,
#[arg(short = 'l', long)]
pub list: bool,
#[arg(long)]
pub exp: bool,
#[arg(long)]
pub imp: bool,
#[arg(long)]
pub all: bool,
}
#[allow(unused_imports)]
pub fn process_args(args: &Args) -> Option<bool> {
use crate::args::{cache, install, list, news, remove, search, update};
if let Some(search_query) = &args.search {
search::handle_search(search_query);
}
if args.clear_cache {
cache::handle_clear_cache();
}
if args.list {
list::handle_list(args.exp, args.imp, args.all);
}
if !args.install.is_empty() {
install::handle_install(&args.install);
}
if let Some(file_path) = &args.install_from_file {
install::handle_install_from_file(file_path);
}
if !args.remove.is_empty() {
remove::handle_remove(&args.remove);
}
if let Some(file_path) = &args.remove_from_file {
tracing::info!(file = %file_path, "Remove from file requested from CLI");
tracing::warn!("Remove from file not yet implemented, falling back to TUI");
}
#[cfg(not(target_os = "windows"))]
if args.update {
update::handle_update(args.no_color);
}
#[cfg(target_os = "windows")]
if args.update {
eprintln!("System update is not supported on Windows");
std::process::exit(1);
}
if args.news {
news::handle_news(args.unread, args.read, args.all_news);
}
None
}