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;
use self::pattern::pattern;
pub mod core;
pub mod garbage_collection;
pub mod history;
pub mod revert;
pub mod utils;
pub 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")]
pattern: Option<String>,
#[arg(short = 'd', long = "path")]
path: Option<PathBuf>,
#[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!("{:#?}", &items);
remove_files(items, cli.recursive, cli.verbose, true).unwrap();
}
if let (Some(pattern_str), Some(path)) = (cli.pattern, cli.path) {
trace!("Pattern: {:#?}, Path: {:#?}", pattern_str, path);
pattern(path.to_str().unwrap().to_string(), pattern_str).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 => {}
}
}