From 90a224f1d574301ca1a5a96c761dcae4bc2d13bd Mon Sep 17 00:00:00 2001 From: jaspersmitNL Date: Fri, 5 Jan 2024 15:50:16 +0100 Subject: [PATCH] update --- src/main.rs | 41 ++++++++++++++++++++++++++++++++++- users.json => test/users.json | 0 2 files changed, 40 insertions(+), 1 deletion(-) rename users.json => test/users.json (100%) diff --git a/src/main.rs b/src/main.rs index 69e72a9..98dbed1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -485,8 +485,47 @@ fn main() { let args = Args::parse(); args.check(); - let source = read_file(args.input); + if args.input.is_dir() && args.output.is_dir() { + println!( + "Converting all files in {} to {}", + args.input.display(), + args.output.display() + ); + + for entry in std::fs::read_dir(args.input).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + + if path.is_file() { + let source = read_file(path.clone()); + let result = match args.mode.as_str() { + "json2ps" => convert_json2ps(source), + "ps2json" => convert_ps2json(source), + _ => panic!("Invalid mode: {}", args.mode), + }; + + let mut output = args.output.clone(); + output.push(path.file_name().unwrap()); + + let mut output = output.to_str().unwrap().to_string(); + + if args.mode == "json2ps" { + output.push_str(".ps1"); + } + + if args.mode == "ps2json" { + output.push_str(".json"); + } + + write_file(PathBuf::from(output), result); + println!("Converted {}", path.display()); + } + } + return; + } + + let source = read_file(args.input); let result = match args.mode.as_str() { "json2ps" => convert_json2ps(source), "ps2json" => convert_ps2json(source), diff --git a/users.json b/test/users.json similarity index 100% rename from users.json rename to test/users.json