Only show vim output on failure (fix #144)
This commit is contained in:
@@ -105,19 +105,7 @@ impl Executor {
|
|||||||
let result = match self {
|
let result = match self {
|
||||||
Executor::Wet(c) => c.spawn().context(ErrorKind::ProcessExecution).map(ExecutorChild::Wet)?,
|
Executor::Wet(c) => c.spawn().context(ErrorKind::ProcessExecution).map(ExecutorChild::Wet)?,
|
||||||
Executor::Dry(c) => {
|
Executor::Dry(c) => {
|
||||||
print!(
|
c.dry_run();
|
||||||
"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!(),
|
|
||||||
};
|
|
||||||
ExecutorChild::Dry
|
ExecutorChild::Dry
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -125,6 +113,17 @@ impl Executor {
|
|||||||
Ok(result)
|
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()`.
|
/// A convinence method for `spawn().wait().check()`.
|
||||||
/// Returns an error if something went wrong during the execution or if the
|
/// Returns an error if something went wrong during the execution or if the
|
||||||
/// process exited with failure.
|
/// 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.
|
/// A struct represending a command. Trying to execute it will just print its arguments.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DryCommand {
|
pub struct DryCommand {
|
||||||
@@ -141,6 +145,24 @@ pub struct DryCommand {
|
|||||||
directory: Option<OsString>,
|
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.
|
/// The Result of spawn. Contains an actual `std::process::Child` if executed by a wet command.
|
||||||
pub enum ExecutorChild {
|
pub enum ExecutorChild {
|
||||||
Wet(Child),
|
Wet(Child),
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
use crate::error::Error;
|
use crate::error::{Error, ErrorKind};
|
||||||
use crate::executor::RunType;
|
use crate::executor::{ExecutorOutput, RunType};
|
||||||
use crate::terminal::print_separator;
|
use crate::terminal::print_separator;
|
||||||
use crate::utils::{require, require_option, PathExt};
|
use crate::utils::{require, require_option, PathExt};
|
||||||
use directories::BaseDirs;
|
use directories::BaseDirs;
|
||||||
use std::fs;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
io::{self, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum PluginFramework {
|
pub enum PluginFramework {
|
||||||
@@ -59,7 +62,7 @@ fn nvimrc(base_dirs: &BaseDirs) -> Option<PathBuf> {
|
|||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, run_type: RunType) -> Result<(), Error> {
|
fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, run_type: RunType) -> Result<(), Error> {
|
||||||
run_type
|
let output = run_type
|
||||||
.execute(&vim)
|
.execute(&vim)
|
||||||
.args(&["-N", "-u"])
|
.args(&["-N", "-u"])
|
||||||
.arg(vimrc)
|
.arg(vimrc)
|
||||||
@@ -72,9 +75,18 @@ fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, ru
|
|||||||
"-s",
|
"-s",
|
||||||
"-V1",
|
"-V1",
|
||||||
])
|
])
|
||||||
.check_run()?;
|
.output()?;
|
||||||
|
|
||||||
println!();
|
if let ExecutorOutput::Wet(output) = output {
|
||||||
|
let status = output.status;
|
||||||
|
if !status.success() {
|
||||||
|
io::stdout().write(&output.stdout).ok();
|
||||||
|
io::stderr().write(&output.stderr).ok();
|
||||||
|
Err(ErrorKind::ProcessFailed(status))?
|
||||||
|
} else {
|
||||||
|
println!("Plugins upgraded")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user