diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/src/main.rs b/src/main.rs index b2fc8a8..010e6f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,11 +39,6 @@ use terminal_size::{terminal_size, Height, Width}; use utils::get_filesystem_devices; use utils::simplify_dir_names; -use crate::node::Node; -use chrono::Local; -use std::fs::File; -use std::io::Write; - static DEFAULT_NUMBER_OF_LINES: usize = 30; static DEFAULT_TERMINAL_WIDTH: usize = 80; @@ -233,18 +228,6 @@ fn main() { let top_level_nodes = walk_it(simplified_dirs, &walk_data); - if config.get_output_json(&options) { - let datetime = Local::now().format("%Y%m%d%H%M%S").to_string(); - let output_filename = format!("node-{}.json", datetime); - let result = output_json(&output_filename, &top_level_nodes); - match result { - Ok(..) => {} - Err(err) => { - eprintln!("Error: {}", err) - } - } - } - let tree = match summarize_file_types { true => get_all_file_types(&top_level_nodes, number_of_lines), false => { @@ -301,13 +284,18 @@ fn main() { output_format, bars_on_right: config.get_bars_on_right(&options), }; - draw_it( - idd, - config.get_no_bars(&options), - terminal_width, - &root_node, - config.get_skip_total(&options), - ) + + if config.get_output_json(&options) { + println!("{}", serde_json::to_string(&root_node).unwrap()); + } else { + draw_it( + idd, + config.get_no_bars(&options), + terminal_width, + &root_node, + config.get_skip_total(&options), + ) + } } } @@ -342,10 +330,3 @@ fn init_rayon(stack_size: &Option<usize>) { } } } - -fn output_json(output_filename: &str, top_level_nodes: &Vec<Node>) -> std::io::Result<()> { - let serialized: String = serde_json::to_string(&top_level_nodes).unwrap(); - let mut file = File::create(output_filename)?; - file.write_all(serialized.as_bytes())?; - Ok(()) -} |