diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs index 71df589a..c45b7a8f 100644 --- a/libimagrt/src/configuration.rs +++ b/libimagrt/src/configuration.rs @@ -152,6 +152,10 @@ impl Configuration { }) } + pub fn editor(&self) -> Option<&String> { + self.editor.as_ref() + } + pub fn config(&self) -> &Value { &self.config } diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index 053fc408..d401940e 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -1,4 +1,6 @@ use std::path::PathBuf; +use std::process::Command; +use std::env; pub use clap::App; @@ -140,6 +142,12 @@ impl<'a> Runtime<'a> { .help("Alternative storepath. Must be specified as full path, can be outside of the RTP") .required(false) .takes_value(true)) + + .arg(Arg::with_name("editor") + .long("editor") + .help("Set editor") + .required(false) + .takes_value(true)) } /** @@ -200,6 +208,19 @@ impl<'a> Runtime<'a> { &self.store } + pub fn editor(&self) -> Option { + self.cli() + .value_of("editor") + .map(String::from) + .or({ + match &self.configuration { + &Some(ref c) => c.editor().map(|s| s.clone()), + _ => None, + } + }) + .or(env::var("EDITOR").ok()) + .map(Command::new) + } }