mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-08-26 02:04:39 +00:00
added json output for further processing using other tools
This commit is contained in:
@@ -3,13 +3,15 @@ use memmap2::Mmap;
|
||||
use std::fs;
|
||||
use std::hash::Hasher;
|
||||
use std::{fs::Metadata, path::PathBuf};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct FileInfo {
|
||||
pub path: PathBuf,
|
||||
pub filemeta: Metadata,
|
||||
pub hash: Option<String>,
|
||||
pub size: u64,
|
||||
#[serde(skip)]
|
||||
pub filemeta: Metadata,
|
||||
}
|
||||
|
||||
impl FileInfo {
|
||||
|
||||
@@ -121,8 +121,14 @@ impl Formatter {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let output_table = Self::generate_table(raw, app_args)?;
|
||||
output_table.printstd();
|
||||
if app_args.json {
|
||||
let output_json = serde_json::to_string_pretty(&raw)?;
|
||||
println!("{}", output_json);
|
||||
return Ok(());
|
||||
} else {
|
||||
let output_table = Self::generate_table(raw, app_args)?;
|
||||
output_table.printstd();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -19,8 +19,12 @@ fn main() -> Result<()> {
|
||||
let results = processor.sizewise()?.hashwise()?;
|
||||
|
||||
match app_args.interactive {
|
||||
false => { Formatter::print(results.files, &app_args)?; }
|
||||
true => { interactive::init(results.files, &app_args)?; }
|
||||
false => {
|
||||
Formatter::print(results.files, &app_args)?;
|
||||
}
|
||||
true => {
|
||||
interactive::init(results.files, &app_args)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -27,6 +27,9 @@ pub struct Params {
|
||||
/// Follow links while scanning directories
|
||||
#[arg(long, short)]
|
||||
pub follow_links: bool,
|
||||
/// print json output
|
||||
#[arg(long)]
|
||||
pub json: bool,
|
||||
}
|
||||
|
||||
impl Params {
|
||||
|
||||
Reference in New Issue
Block a user