2021-10-07 01:41:54 -07:00
|
|
|
use schala_repl::{run_noninteractive, start_repl, ProgrammingLanguageInterface};
|
2017-10-12 02:13:55 -07:00
|
|
|
|
2021-10-07 02:19:24 -07:00
|
|
|
use std::path::PathBuf;
|
2021-10-07 01:41:54 -07:00
|
|
|
use std::process::exit;
|
2017-10-26 02:03:47 -07:00
|
|
|
|
2015-07-16 01:40:37 -07:00
|
|
|
fn main() {
|
2021-10-07 01:41:54 -07:00
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
let matches = command_line_options()
|
|
|
|
.parse(&args[1..])
|
|
|
|
.unwrap_or_else(|e| {
|
|
|
|
eprintln!("Error parsing options: {}", e);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
if matches.opt_present("help") {
|
|
|
|
println!("{}", command_line_options().usage("Schala metainterpreter"));
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
let langs: Vec<Box<dyn ProgrammingLanguageInterface>> =
|
|
|
|
vec![Box::new(schala_lang::Schala::new())];
|
|
|
|
|
|
|
|
if matches.free.is_empty() {
|
|
|
|
start_repl(langs);
|
|
|
|
} else {
|
2021-10-07 02:19:24 -07:00
|
|
|
let paths = matches.free.iter().map(PathBuf::from).collect();
|
|
|
|
run_noninteractive(paths, langs);
|
2021-10-07 01:41:54 -07:00
|
|
|
}
|
2017-10-23 20:51:08 -07:00
|
|
|
}
|
|
|
|
|
2021-10-07 01:41:54 -07:00
|
|
|
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
|
|
|
|
}
|