Add editor()

Signed-off-by: Kai Sickeler <k.sickeler@gmail.com>
This commit is contained in:
Kai Sickeler 2016-03-21 10:19:03 +01:00 committed by Matthias Beyer
parent fcfeb7ff48
commit b315cb7fd0
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)
}
} }