Merge pull request #261 from matthiasbeyer/libimagrt/editor

Add editor()
This commit is contained in:
Matthias Beyer 2016-03-23 18:25:04 +01:00
commit 958171fc54
2 changed files with 25 additions and 0 deletions

View file

@ -152,6 +152,10 @@ impl Configuration {
}) })
} }
pub fn editor(&self) -> Option<&String> {
self.editor.as_ref()
}
pub fn config(&self) -> &Value { pub fn config(&self) -> &Value {
&self.config &self.config
} }

View file

@ -1,4 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command;
use std::env;
pub use clap::App; 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") .help("Alternative storepath. Must be specified as full path, can be outside of the RTP")
.required(false) .required(false)
.takes_value(true)) .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 &self.store
} }
pub fn editor(&self) -> Option<Command> {
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)
}
} }