Add getopts

This commit is contained in:
greg 2016-12-28 15:56:02 -08:00
parent c389b44bf8
commit aac3ca40fe
2 changed files with 17 additions and 7 deletions

View File

@ -8,4 +8,5 @@ authors = ["greg <greg.shuflin@protonmail.com>"]
simplerepl = { path = "../simplerepl" }
llvm-sys = "*"
take_mut = "0.1.3"
getopts = "*"

View File

@ -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<String> = 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) {