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" } simplerepl = { path = "../simplerepl" }
llvm-sys = "*" llvm-sys = "*"
take_mut = "0.1.3" take_mut = "0.1.3"
getopts = "*"

View File

@ -1,6 +1,6 @@
#![feature(advanced_slice_patterns, slice_patterns, box_patterns)] #![feature(advanced_slice_patterns, slice_patterns, box_patterns)]
extern crate simplerepl; extern crate simplerepl;
extern crate getopts;
use std::path::Path; use std::path::Path;
use std::fs::File; use std::fs::File;
@ -22,12 +22,21 @@ mod compilation;
mod llvm_wrap; mod llvm_wrap;
fn main() { fn main() {
let args: Vec<String> = std::env::args().collect(); let option_matches = program_options().parse(std::env::args()).expect("Could not parse options");
if let Some(filename) = args.get(1) { match option_matches.free[..] {
run_noninteractive(filename); [] | [_] => {
} else { run_repl();
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) { fn run_noninteractive(filename: &String) {