file/
file.rs

1use std::env;
2use std::fs::File;
3use std::io::{self, BufRead};
4use std::path::Path;
5
6/// Reads a file containing multiple spots line by line.
7/// Each successfully parsed spot will be printed to stdout in their json format.
8fn main() {
9    let args: Vec<String> = env::args().collect();
10
11    if args.len() != 2 {
12        eprintln!("Invalid number of arguments.");
13        eprintln!("Usage: {} <file>", args[0]);
14    } else {
15        let filepath = Path::new(&args[1]);
16        let file = File::open(filepath).expect("Failed to open file");
17        let reader = io::BufReader::new(file).lines();
18
19        for line in reader {
20            match dxclparser::parse(line.unwrap().trim().trim_end_matches('\u{0007}')) {
21                Ok(spot) => {
22                    println!("{}", spot.to_json());
23                }
24                Err(e) => {
25                    eprintln!("Failed to parse spot ({})", e);
26                }
27            }
28        }
29    }
30}