use clap::{Parser, Subcommand};
use log::trace;
use std::fs::remove_dir_all;
use std::path::{Path, PathBuf};
use self::core::remove_files;
use self::revert::read_json_history;
pub mod core;
pub mod garbage_collection;
pub mod history;
pub mod revert;
pub mod utils;
mod pattern;
#[derive(Parser)]
#[command(
version,
name = "roxide",
author = "Abhinandh S <ugabhi@proton.me>",
about = "roxide",
//long_about = "By default, roxide does not remove directories.Use the --recursive (-r) option to remove each listed directory, too, along with all of its contents.\n
// To remove a file whose name starts with a '-', for example '-foo',\n
// use one of these commands:\n
// roxide -- -foo\n
// roxide ./-foo\n
// If you use roxide to remove a file, it might be possible to recover the file/directory.\n
// Files are trashed to XDG specified trash directory.\n
// Example:\n
// `$HOME`/.local/share/Trash/files\n"
)]
struct Cli {
file: Option<Vec<PathBuf>>,
#[arg(short, long)]
recursive: bool,
#[arg(short = 'p', long = "pattern", value_name = "PATTERN")] pattern: Option<String>,
#[arg(short, long, value_name = "FILE")]
force: Option<Vec<PathBuf>>,
#[arg(short, long)]
verbose: bool,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Revert {},
}
fn main() {
env_logger::init();
let cli = Cli::parse();
if let Some(items) = cli.file {
trace!("got item:{:?} and recursive is {:?}", &items, cli.recursive);
remove_files(
items,
cli.recursive,
cli.pattern,
cli.verbose,
)
.unwrap();
}
if let Some(forece_file) = cli.force {
for i in forece_file {
if Path::new(&i).exists() {
remove_dir_all(i).unwrap();
} else {
println!("Path didnt exists");
}
}
}
match &cli.command {
Some(Commands::Revert {}) => {
read_json_history().unwrap();
}
None => {}
}
}