let args: Vec<String> = env::args().collect();
let mut opts = getopts::Options::new();
opts.optflag("e", "", "Edit nfp config");
let matches = opts.parse(&args[1..])?;
if matches.opt_present("e") {
let command = match env::var("VISUAL").or(env::var("EDITOR")) {
Ok(s) => s,
Err(_) => return Err("Expect $VISUAL or $EDITOR to be set.".into()),
};
let status = Command::new(&command)
.args(vec![config::path()?])
.status()?;
if !status.success() {
return Err(format!("Failed executing `{}`", &command).into());
}
if let Err(e) = config::load() {
eprintln!("Warning: config {} couldn't be parsed.", config::path()?);
return Err(e.into());
}
println!("New config {} installed", config::path()?);
return Ok(());
// Expecting a running instance of the daemon to refresh itself if the
// config has changed.
//
// TODO: retain working config in `run()` somehow?
// - or may be just not crash on a broken config!
// TODO: example config if doesn't exist
}