diff --git a/Cargo.toml b/Cargo.toml index 2249978..bea3eb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ authors = ["greg "] simplerepl = { path = "../simplerepl" } llvm-sys = "*" take_mut = "0.1.3" +getopts = "*" diff --git a/src/main.rs b/src/main.rs index e2dd182..33d1db3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![feature(advanced_slice_patterns, slice_patterns, box_patterns)] - extern crate simplerepl; +extern crate getopts; use std::path::Path; use std::fs::File; @@ -22,12 +22,21 @@ mod compilation; mod llvm_wrap; fn main() { - let args: Vec = std::env::args().collect(); - if let Some(filename) = args.get(1) { - run_noninteractive(filename); - } else { - run_repl(); - } + let option_matches = program_options().parse(std::env::args()).expect("Could not parse options"); + match option_matches.free[..] { + [] | [_] => { + run_repl(); + }, + [_, ref filename, ..] => { + run_noninteractive(filename); + } + }; +} + +fn program_options() -> getopts::Options { + let mut options = getopts::Options::new(); + options.optflag("i", "interpret", "Interpret source file instead of compiling"); + options } fn run_noninteractive(filename: &String) {