List of paths
This commit is contained in:
parent
6012e8cf9d
commit
cd4045b8e7
@ -1,8 +1,5 @@
|
||||
#![feature(box_patterns, box_syntax, proc_macro_hygiene, decl_macro)]
|
||||
#![feature(plugin)]
|
||||
extern crate colored;
|
||||
extern crate itertools;
|
||||
extern crate linefeed;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
@ -13,7 +10,7 @@ extern crate serde_json;
|
||||
use std::collections::HashSet;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
mod language;
|
||||
@ -32,16 +29,18 @@ pub fn start_repl(langs: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
||||
repl.run_repl();
|
||||
}
|
||||
|
||||
//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
|
||||
pub fn run_noninteractive(filenames: Vec<PathBuf>, languages: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
||||
// for now, ony do something with the first filename
|
||||
|
||||
let filename = &filenames[0];
|
||||
let ext = filename
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or_else(|| {
|
||||
println!("Source file lacks extension");
|
||||
println!("Source file `{}` has no extension.", filename.display());
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let mut language = Box::new(
|
||||
languages
|
||||
.into_iter()
|
||||
@ -52,7 +51,7 @@ pub fn run_noninteractive(filename: &str, languages: Vec<Box<dyn ProgrammingLang
|
||||
}),
|
||||
);
|
||||
|
||||
let mut source_file = File::open(path).unwrap();
|
||||
let mut source_file = File::open(filename).unwrap();
|
||||
let mut buffer = String::new();
|
||||
source_file.read_to_string(&mut buffer).unwrap();
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
use schala_repl::{run_noninteractive, start_repl, ProgrammingLanguageInterface};
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
fn main() {
|
||||
@ -22,7 +23,8 @@ fn main() {
|
||||
if matches.free.is_empty() {
|
||||
start_repl(langs);
|
||||
} else {
|
||||
run_noninteractive(&matches.free[0], langs);
|
||||
let paths = matches.free.iter().map(PathBuf::from).collect();
|
||||
run_noninteractive(paths, langs);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user