dx-cli 0.3.1

faster dx with obj c ffi bindings
#![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 mut result_data = ;
    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)| {
                    // props.key
                    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);


                    // let formatted = cformat!("gello {:?}", modified_date);

                    // let formatted_date = datetime.format("%Y-%m-%d %H:%M:%S").to_string();
                    // let fmx =
                    // format_iso(UNIX_EPOCH + Duration::from_millis(*modified_date as u64), 0);

                    table.add_row(row![
                        bFc->name,
                        ByteSize::b(*logical_size).to_string(),
                        ByteSize::b(*physical_size).to_string(),
                        modified_date
                        // formatted
                        // NaiveDateTime::from_timestamp((*modified_date as i64) / 1000, 0)
                        //     .format("%Y-%m-%d %H:%M:%S")
                        //     .to_string()
                    ]);
                });
            table.printstd();
            cprintln!(
                "<bold>time elapsed: <y>{}ms </yellow>",
                now.elapsed().as_micros() as f64 / 1000.0
            );
        }
        Err(e) => {
            println!("error: {:?}", e);
        }
    }
    // result_data.unwrap();
}