error handling fixup also read config from user config directory

master
rasul 5 years ago
parent 63e98f2c01
commit a8527f4843

@ -1,5 +1,6 @@
extern crate chrono; extern crate chrono;
extern crate colored; extern crate colored;
extern crate dirs;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate serde; extern crate serde;
@ -13,6 +14,10 @@ mod logger;
mod proc; mod proc;
mod result; mod result;
use std::path::PathBuf;
use dirs::config_dir;
use apps::Apps; use apps::Apps;
use proc::Proc; use proc::Proc;
use result::Result; use result::Result;
@ -23,7 +28,15 @@ fn main() {
std::process::exit(1); std::process::exit(1);
} }
match startup() { let apps_file: PathBuf = match config_dir() {
Some(mut d) => {
d.push("sup.toml");
d
}
None => PathBuf::from("sup.toml"),
};
match startup(apps_file) {
Ok(p) => { Ok(p) => {
info!("shutting down"); info!("shutting down");
for mut proc in p { for mut proc in p {
@ -37,10 +50,9 @@ fn main() {
}; };
} }
fn startup() -> Result<Vec<Proc>> { fn startup(apps_file: PathBuf) -> Result<Vec<Proc>> {
let apps = Apps::load("sup.toml")?; let apps = Apps::load(apps_file)?;
let (procs, holds) = apps.start(); let (procs, holds) = apps.start();
let procs = apps.run(procs, holds)?; let procs = apps.run(procs, holds)?;
Ok(procs) Ok(procs)
} }

Loading…
Cancel
Save