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