#![allow(
unused_variables,
unreachable_code,
unused_imports,
dead_code,
unused_parens,
deprecated
)]
use bytesize::ByteSize;
use itertools::Itertools;
use prettytable::{format, row};
use dx_cli::ds_parser::get_ds_cache;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant, UNIX_EPOCH};
extern crate color_print;
use color_print::{cformat, cprint, cprintln};
use std::collections::HashMap;
use std::convert::TryInto;
use std::io::{Error, Read};
use std::{error, io, time};
extern crate prettytable;
use prettytable::{Cell, Row, Table};
fn main() {
let arg_path = std::env::args().nth(1);
let path = match arg_path {
Some(path) => PathBuf::from(path),
None => std::env::current_dir().unwrap(),
};
let ds_store_path = if path.is_dir() {
path.join(".DS_Store")
} else {
path.to_path_buf()
};
if !ds_store_path.exists() {
println!("no exists");
return;
}
let now = Instant::now();
match get_ds_cache(&path) {
Ok(result_data) => {
let files = result_data.get_files();
let mut table = Table::new();
table.add_row(row![b => "file", "logicalSize", "physicalSize", "modifiedDate"]);
files
.iter()
.sorted_by_key(|(name, _)| name.to_string())
.for_each(|(name, props)| {
let logical_size = props.get("logical_size").unwrap_or(&0);
let physical_size = props.get("physical_size").unwrap_or(&0);
let modified_date = props.get("modified_date").unwrap_or(&0);
table.add_row(row![
bFc->name,
ByteSize::b(*logical_size).to_string(),
ByteSize::b(*physical_size).to_string(),
modified_date
]);
});
table.printstd();
cprintln!(
"<bold>time elapsed: <y>{}ms </yellow>",
now.elapsed().as_micros() as f64 / 1000.0
);
}
Err(e) => {
println!("error: {:?}", e);
}
}
}