mirror of
https://github.com/MeiK2333/river.git
synced 2025-11-04 14:49:40 +08:00
Update
This commit is contained in:
parent
66dcafd389
commit
74bbf6432d
@ -1,10 +1,12 @@
|
|||||||
use std::result;
|
use std::result;
|
||||||
|
use std::fs;
|
||||||
use yaml_rust::{ScanError, Yaml, YamlLoader};
|
use yaml_rust::{ScanError, Yaml, YamlLoader};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
YamlScanError(ScanError),
|
YamlScanError(ScanError),
|
||||||
YamlParseError(String),
|
YamlParseError(String),
|
||||||
|
ReadFileError,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
@ -86,6 +88,14 @@ impl Config {
|
|||||||
|
|
||||||
Ok(Config { languages })
|
Ok(Config { languages })
|
||||||
}
|
}
|
||||||
|
pub fn load_from_file(filename: &str) -> Result<Config> {
|
||||||
|
let contents = match fs::read_to_string(filename) {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(_) => return Err(Error::ReadFileError),
|
||||||
|
};
|
||||||
|
let config = Config::load_yaml(&contents)?;
|
||||||
|
Ok(config)
|
||||||
|
}
|
||||||
pub fn default() -> Result<Config> {
|
pub fn default() -> Result<Config> {
|
||||||
let config_yaml = "
|
let config_yaml = "
|
||||||
languages:
|
languages:
|
||||||
|
|||||||
26
src/main.rs
26
src/main.rs
@ -1,10 +1,11 @@
|
|||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
mod runner;
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod runner;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
@ -15,11 +16,22 @@ fn main() {
|
|||||||
data.insert("world".to_string(), "世界!".to_string());
|
data.insert("world".to_string(), "世界!".to_string());
|
||||||
println!("{}", handlebars.render("t1", &data).unwrap());
|
println!("{}", handlebars.render("t1", &data).unwrap());
|
||||||
|
|
||||||
let _config = match config::Config::default() {
|
let args: Vec<String> = env::args().collect();
|
||||||
Ok(value) => value,
|
let _config = if args.len() > 1 {
|
||||||
Err(err) => {
|
match config::Config::load_from_file(&args[1]) {
|
||||||
println!("{:?}", err);
|
Ok(value) => value,
|
||||||
return
|
Err(err) => {
|
||||||
|
println!("{:?}", err);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match config::Config::default() {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(err) => {
|
||||||
|
println!("{:?}", err);
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
9
tests/config.yml
Normal file
9
tests/config.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
languages:
|
||||||
|
- language: c
|
||||||
|
version: 7.5.0
|
||||||
|
compile_command: /usr/bin/gcc {{filename}} -o a.out
|
||||||
|
run_command: ./a.out
|
||||||
|
- language: python
|
||||||
|
version: 3.6.9
|
||||||
|
compile_command: /usr/bin/python3 -m compileall {{filename}}
|
||||||
|
run_command: /use/bin/python3 {{filename}}
|
||||||
Loading…
Reference in New Issue
Block a user