Browse Source

bump: rust-based toJSON

dev
Dnomd343 2 years ago
parent
commit
c04201aab5
  1. 36
      to-json/src/main.rs

36
to-json/src/main.rs

@ -1,4 +1,3 @@
use std::fs::{read, read_to_string};
use std::io::Read; use std::io::Read;
use serde_json as json; use serde_json as json;
use serde_yaml as yaml; use serde_yaml as yaml;
@ -48,32 +47,11 @@ fn read_file(path: &str) -> String { // read file content
} }
fn main() { fn main() {
let args: Vec<String> = std::env::args().collect(); // input arguments
let file_name = "test.json_"; if args.len() < 2 { // missing arguments
println!("usage: toJSON [file]");
let content = read_file(file_name); std::process::exit(0);
}
println!("{}", content); let content = read_file(&args[1].clone()[..]); // read file content
println!("{}", to_json(&content[..])); // convert to JSON format
// match std::fs::File::open(file_name) {
// Ok(file) => {
// read_to_string()
// },
// Err(_) => std::process::exit(FILE_ERROR),
// }
// let mut file = std::fs::File::open(file_name).unwrap();
// let mut contents = String::new();
// file.read_to_string(&mut contents).unwrap();
// println!("{}", contents);
// match std::fs::File::open(file_name) {
// Ok(mut file) => {
// let mut contents = String::new();
// file.read_to_string(&mut contents).unwrap();
// println!("{}", contents);
// },
// Err(_) => std::process::exit(FILE_ERROR),
// }
} }

Loading…
Cancel
Save