use otomescript::{repl, run, Context, Scope};
use std::fs::read_to_string;

fn main() {
    let file = std::env::args().nth(1);
    if let Some(file) = file {
        let res = if file == "-e" {
            let code = &std::env::args().collect::<Vec<String>>()[2..].join(" ");
            run(code.as_str())
        } else {
            run(&read_to_string(file).unwrap())
        };
        match res {
            Ok(l) => {
                if !l.is_empty() {
                    println!("{}", l.join("\n"))
                }
            }
            Err(e) => println!("{} at {}:{}", e.0, e.1 .0, e.1 .1),
        }
    } else {
        repl(&mut Context::default(), &mut Scope::new())
    }
}