diff --git a/src/main.rs b/src/main.rs index 9ae382d..a82a618 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,22 @@ +use std::{env, fs, process}; + fn main() { // Get the schema file from the command line arguments or use the default. let default_schema_file = "schema.graphql".to_string(); - let schema_file = &std::env::args().nth(1).unwrap_or(default_schema_file); - println!("schema_file: {}", schema_file); + let schema_file = &env::args().nth(1).unwrap_or(default_schema_file); + dbg!("schema_file: {}", schema_file); // Read the schema file and parse it into a schema object. - let result = std::fs::read_to_string(schema_file); - if result.is_err() { - println!("Error reading schema file: {}", result.err().unwrap()); - std::process::exit(error_codes::ERROR_SCHEMA_FILE_INVALID); - } - - let schema_file = result.unwrap(); - let result = minigraf::parse_schema(&schema_file); - if result.is_err() { - println!("Error parsing schema file: {}", result.err().unwrap()); - std::process::exit(minigraf::error_codes::ERROR_SCHEMA_INVALID); - } + let schema_file = fs::read_to_string(schema_file).unwrap_or_else(|err| { + eprintln!("Error reading schema file: {}", err); + process::exit(error_codes::ERROR_SCHEMA_FILE_INVALID); + }); - let schema = result.unwrap(); - println!("schema: {:#?}", schema); + let schema = minigraf::parse_schema(&schema_file).unwrap_or_else(|err| { + eprintln!("Error parsing schema file: {}", err); + process::exit(minigraf::error_codes::ERROR_SCHEMA_INVALID); + }); + dbg!("schema: {:#?}", schema); } mod error_codes {