Refactor main.rs
main.rs controls options, calls into interactive or non-interactive start function from schala-repl.
This commit is contained in:
@@ -9,7 +9,6 @@ resolver = "2"
|
||||
llvm-sys = "70.0.2"
|
||||
take_mut = "0.2.2"
|
||||
itertools = "0.10"
|
||||
getopts = "0.2.18"
|
||||
lazy_static = "0.2.8"
|
||||
maplit = "*"
|
||||
colored = "1.8"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#![feature(box_patterns, box_syntax, proc_macro_hygiene, decl_macro)]
|
||||
#![feature(plugin)]
|
||||
extern crate colored;
|
||||
extern crate getopts;
|
||||
extern crate itertools;
|
||||
extern crate linefeed;
|
||||
|
||||
@@ -29,30 +28,12 @@ include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
||||
const VERSION_STRING: &'static str = "0.1.0";
|
||||
|
||||
pub fn start_repl(langs: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
||||
let options = command_line_options()
|
||||
.parse(std::env::args())
|
||||
.unwrap_or_else(|e| {
|
||||
println!("{:?}", e);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
if options.opt_present("help") {
|
||||
println!("{}", command_line_options().usage("Schala metainterpreter"));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
match options.free[..] {
|
||||
[] | [_] => {
|
||||
let mut repl = repl::Repl::new(langs);
|
||||
repl.run_repl();
|
||||
}
|
||||
[_, ref filename, ..] => {
|
||||
run_noninteractive(filename, langs);
|
||||
}
|
||||
};
|
||||
let mut repl = repl::Repl::new(langs);
|
||||
repl.run_repl();
|
||||
}
|
||||
|
||||
fn run_noninteractive(filename: &str, languages: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
||||
//TODO should really expect a list of paths
|
||||
pub fn run_noninteractive(filename: &str, languages: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
||||
let path = Path::new(filename);
|
||||
let ext = path
|
||||
.extension()
|
||||
@@ -87,9 +68,3 @@ fn run_noninteractive(filename: &str, languages: Vec<Box<dyn ProgrammingLanguage
|
||||
};
|
||||
}
|
||||
|
||||
fn command_line_options() -> getopts::Options {
|
||||
let mut options = getopts::Options::new();
|
||||
options.optflag("h", "help", "Show help text");
|
||||
options.optflag("w", "webapp", "Start up web interpreter");
|
||||
options
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user