summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorsyn <isaqtm@gmail.com>2020-02-14 13:09:44 +0300
committersyn <isaqtm@gmail.com>2020-02-14 13:09:44 +0300
commit3da19e8603c00c02ec7e24ea8910a7c386b09018 (patch)
treebb9740afd63099a6038c22b82cf84cba8c9218e9 /src/main.rs
parent30e1e3a13dc19c47afc517d1178e1dbf5b401596 (diff)
downloadevr-3da19e8603c00c02ec7e24ea8910a7c386b09018.tar.gz
Improve error handling
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs
index 1621e1b..4eeb298 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ extern crate lazy_static;
use clap::{ AppSettings, App, Arg };
use env_logger;
use log::{ error };
+use std::io::prelude::*;
mod conf;
mod backends;
@@ -41,19 +42,28 @@ fn main() {
.into();
let config = conf::get_conf();
- let result =
- if src_path.exists() {
- config.run(
- &src_path,
- matches.is_present("time"),
- matches.is_present("mem")
- )
+ if src_path.exists() {
+ if let Some(backend) = config.get_backend(&src_path) {
+ match backend.run(&src_path) {
+ Ok(status) => {
+ if matches.is_present("time") {
+ println!("wall time: {:?}", status.wall_time);
+ }
+ if matches.is_present("mem") {
+ println!("rss: {}K", status.usage.ru_maxrss);
+ }
+ },
+ Err(err) => error!("{}", err)
+ };
} else {
- config.make(&src_path)
- };
-
- match result {
- Ok(_) => {},
- Err(err) => error!("{}", err)
- }
+ error!("could not match backend");
+ }
+ } else {
+ let template = config.get_template(&src_path).as_bytes();
+ if let Err(err) =
+ std::fs::File::create(&src_path)
+ .and_then(|mut file| file.write_all(template)) {
+ error!("{}", err);
+ }
+ };
}