Only show vim output on failure (fix #144)

This commit is contained in:
Roey Darwish Dror
2019-05-16 11:08:52 +03:00
parent d2dfe470db
commit c0c155fc8b
2 changed files with 53 additions and 19 deletions

View File

@@ -105,19 +105,7 @@ impl Executor {
let result = match self {
Executor::Wet(c) => c.spawn().context(ErrorKind::ProcessExecution).map(ExecutorChild::Wet)?,
Executor::Dry(c) => {
print!(
"Dry running: {} {}",
c.program.to_string_lossy(),
c.args
.iter()
.map(|a| String::from(a.to_string_lossy()))
.collect::<Vec<String>>()
.join(" ")
);
match &c.directory {
Some(dir) => println!(" in {}", dir.to_string_lossy()),
None => println!(),
};
c.dry_run();
ExecutorChild::Dry
}
};
@@ -125,6 +113,17 @@ impl Executor {
Ok(result)
}
/// See `std::process::Command::output`
pub fn output(&mut self) -> Result<ExecutorOutput, Error> {
match self {
Executor::Wet(c) => Ok(ExecutorOutput::Wet(c.output().context(ErrorKind::ProcessExecution)?)),
Executor::Dry(c) => {
c.dry_run();
Ok(ExecutorOutput::Dry)
}
}
}
/// A convinence method for `spawn().wait().check()`.
/// Returns an error if something went wrong during the execution or if the
/// process exited with failure.
@@ -133,6 +132,11 @@ impl Executor {
}
}
pub enum ExecutorOutput {
Wet(std::process::Output),
Dry,
}
/// A struct represending a command. Trying to execute it will just print its arguments.
#[derive(Default)]
pub struct DryCommand {
@@ -141,6 +145,24 @@ pub struct DryCommand {
directory: Option<OsString>,
}
impl DryCommand {
fn dry_run(&self) {
print!(
"Dry running: {} {}",
self.program.to_string_lossy(),
self.args
.iter()
.map(|a| String::from(a.to_string_lossy()))
.collect::<Vec<String>>()
.join(" ")
);
match &self.directory {
Some(dir) => println!(" in {}", dir.to_string_lossy()),
None => println!(),
};
}
}
/// The Result of spawn. Contains an actual `std::process::Child` if executed by a wet command.
pub enum ExecutorChild {
Wet(Child),