#![allow(unused)]
use std::{fs, thread, path::PathBuf, env, time, process};
use std::env::{current_dir, set_current_dir};
use sizer::entry;
use clap::{Parser, Subcommand, Command, arg};
use log;
fn main(){
env::set_var("RUST_LOG", "debug");
env_logger::init();
let matches = Command::new("sizer")
.version("1.0")
.author("Buki O. <ebuka2264@yahoo.com>")
.about("This tool searches for files bigger than 100mb in a given directory or the whole file system if no filepath is given")
.arg(arg!(-p --path <VALUE> "The filepath that you want to perform a search on").required(false))
.arg(arg!(-s --size <VALUE> "The size of the file in megabyte that you want to log when found, defaults to 100mb by default").required(false))
.get_matches();
let path = matches.get_one::<String>("path");
match path {
Some(path) => {
let size: Option<&String> = matches.get_one::<String>("size");
if size.is_none() || size.unwrap().parse::<i64>().is_err(){
log::error!("❌invalid file size ......❌");
thread::sleep(time::Duration::from_millis(1000));
log::info!("📣defaulting to 100mb💣");
thread::sleep(time::Duration::from_millis(1000));
let home_dir = PathBuf::from(path);
entry(&home_dir, None);
}else{
let home_dir = PathBuf::from(path);
entry(&home_dir, size);
}}
None => {
let size: Option<&String> = matches.get_one::<String>("size"); if size.is_none() || size.unwrap().parse::<i64>().is_err(){
log::error!("❌invalid file size ......❌");
thread::sleep(time::Duration::from_millis(1000));
log::info!("📣defaulting to 100mb🔊");
thread::sleep(time::Duration::from_millis(1000));
let root_dir = PathBuf::from("/");
entry(&root_dir, None);
}else{
let root_dir = PathBuf::from("/");
entry(&root_dir, size);
}
}
}
}
fn old_main(){
env_logger::init();
let args:Vec<String> = env::args().collect();
println!("{args:?}");
if args.len() > 2 {
log::error!("wrong arguement, please use file path as an arguement");
process::exit(1)
}else if args.len() == 2 {
let mut args = args.iter();
args.next();
let home_dir = PathBuf::from(args.next().unwrap());
}else{
let current_dir = current_dir().unwrap();
}
}