add bitsy-parse executable for independent testing of import/export

This commit is contained in:
Max Bradbury 2020-07-26 12:36:29 +01:00
parent c05010432a
commit f2ae43e85f
1 changed files with 15 additions and 0 deletions

15
src/bin/bitsy-parse.rs Normal file
View File

@ -0,0 +1,15 @@
extern crate bitsy_parser;
use bitsy_parser::game::Game;
use std::{env, fs};
const SYNTAX_ERROR: &str = "Usage: `bitsy-parse input.bitsy output.bitsy`";
/// simply parses and re-exports a game. use to test whether output matches input.
fn main() {
let input = env::args().nth(1).expect(SYNTAX_ERROR);
let output = env::args().nth(2).expect(SYNTAX_ERROR);
let game = Game::from(fs::read_to_string(input).unwrap()).unwrap();
fs::write(output, game.to_string()).expect("Failed to write output file");
}