Files
topgrade/src/steps.rs

86 lines
2.0 KiB
Rust
Raw Normal View History

2018-06-17 11:43:25 +03:00
use super::utils::Check;
2018-06-06 15:32:38 +03:00
use failure;
use std::env::home_dir;
2018-06-06 15:32:38 +03:00
use std::path::PathBuf;
use std::process::Command;
use utils::is_ancestor;
2018-06-06 15:32:38 +03:00
const EMACS_UPGRADE: &str = include_str!("emacs.el");
pub fn run_cargo_update(cargo_update: &PathBuf) -> Result<(), failure::Error> {
Command::new(&cargo_update)
2018-06-11 15:45:26 +03:00
.args(&["install-update", "--git", "--all"])
2018-06-06 15:32:38 +03:00
.spawn()?
.wait()?
.check()?;
Ok(())
}
pub fn run_emacs(emacs: &PathBuf, init: &PathBuf) -> Result<(), failure::Error> {
Command::new(&emacs)
2018-07-03 14:33:48 +03:00
.args(&["--batch", "-l", init.to_str().unwrap(), "--eval", EMACS_UPGRADE])
2018-06-06 15:32:38 +03:00
.spawn()?
.wait()?
.check()?;
2018-06-07 08:51:16 +03:00
Ok(())
}
2018-07-03 14:33:48 +03:00
pub fn run_vim(vim: &PathBuf, vimrc: &PathBuf, upgrade_command: &str) -> Result<(), failure::Error> {
2018-06-07 08:51:16 +03:00
Command::new(&vim)
.args(&[
"-N",
"-u",
vimrc.to_str().unwrap(),
"-c",
upgrade_command,
"-c",
"quitall",
"-e",
"-s",
"-V1",
])
.spawn()?
.wait()?
.check()?;
2018-06-06 15:32:38 +03:00
2018-06-09 20:52:42 +03:00
println!("");
2018-06-06 15:32:38 +03:00
Ok(())
}
pub fn run_apm(apm: &PathBuf) -> Result<(), failure::Error> {
Command::new(&apm)
.args(&["upgrade", "--confirm=false"])
.spawn()?
.wait()?
.check()?;
Ok(())
}
2018-06-07 22:36:32 +03:00
pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> {
if is_ancestor(&home_dir().unwrap(), &rustup) {
2018-07-03 14:33:48 +03:00
Command::new(rustup).args(&["self", "update"]).spawn()?.wait()?.check()?;
}
2018-06-07 22:36:32 +03:00
Command::new(rustup).arg("update").spawn()?.wait()?.check()?;
Ok(())
}
2018-06-06 15:32:38 +03:00
pub fn run_homebrew(homebrew: &PathBuf) -> Result<(), failure::Error> {
2018-07-03 14:33:48 +03:00
Command::new(&homebrew).arg("update").spawn()?.wait()?.check()?;
2018-06-06 15:32:38 +03:00
2018-07-03 14:33:48 +03:00
Command::new(&homebrew).arg("upgrade").spawn()?.wait()?.check()?;
2018-06-06 15:32:38 +03:00
Ok(())
}
pub fn run_custom_command(command: &str) -> Result<(), failure::Error> {
2018-07-03 14:33:48 +03:00
Command::new("sh").arg("-c").arg(command).spawn()?.wait()?.check()?;
Ok(())
}