Dry run (fixes #22)
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
use super::executor::Executor;
|
||||
use super::terminal::Terminal;
|
||||
use super::utils;
|
||||
use super::utils::{Check, PathExt};
|
||||
use super::utils::{self, Check, PathExt};
|
||||
use directories::BaseDirs;
|
||||
use failure::Error;
|
||||
use std::process::Command;
|
||||
|
||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||
|
||||
#[must_use]
|
||||
pub fn run_cargo_update(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
pub fn run_cargo_update(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(cargo_update) = base_dirs.home_dir().join(".cargo/bin/cargo-install-update").if_exists() {
|
||||
terminal.print_separator("Cargo");
|
||||
|
||||
let success = || -> Result<(), Error> {
|
||||
Command::new(cargo_update)
|
||||
Executor::new(cargo_update, dry_run)
|
||||
.args(&["install-update", "--git", "--all"])
|
||||
.spawn()?
|
||||
.wait()?
|
||||
@@ -29,13 +28,13 @@ pub fn run_cargo_update(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(emacs) = utils::which("emacs") {
|
||||
if let Some(init_file) = base_dirs.home_dir().join(".emacs.d/init.el").if_exists() {
|
||||
terminal.print_separator("Emacs");
|
||||
|
||||
let success = || -> Result<(), Error> {
|
||||
Command::new(&emacs)
|
||||
Executor::new(&emacs, dry_run)
|
||||
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
|
||||
.spawn()?
|
||||
.wait()?
|
||||
@@ -51,12 +50,12 @@ pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option<(&'sta
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_apm(terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
pub fn run_apm(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(apm) = utils::which("apm") {
|
||||
terminal.print_separator("Atom Package Manager");
|
||||
|
||||
let success = || -> Result<(), Error> {
|
||||
Command::new(&apm)
|
||||
Executor::new(&apm, dry_run)
|
||||
.args(&["upgrade", "--confirm=false"])
|
||||
.spawn()?
|
||||
.wait()?
|
||||
@@ -72,20 +71,20 @@ pub fn run_apm(terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(rustup) = utils::which("rustup") {
|
||||
terminal.print_separator("rustup");
|
||||
|
||||
let success = || -> Result<(), Error> {
|
||||
if rustup.is_descendant_of(base_dirs.home_dir()) {
|
||||
Command::new(&rustup)
|
||||
Executor::new(&rustup, dry_run)
|
||||
.args(&["self", "update"])
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.check()?;
|
||||
}
|
||||
|
||||
Command::new(&rustup).arg("update").spawn()?.wait()?.check()?;
|
||||
Executor::new(&rustup, dry_run).arg("update").spawn()?.wait()?.check()?;
|
||||
Ok(())
|
||||
}().is_ok();
|
||||
|
||||
@@ -96,9 +95,14 @@ pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal) -> Option<(&'st
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal) -> Result<(), Error> {
|
||||
pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal, dry_run: bool) -> Result<(), Error> {
|
||||
terminal.print_separator(name);
|
||||
Command::new("sh").arg("-c").arg(command).spawn()?.wait()?.check()?;
|
||||
Executor::new("sh", dry_run)
|
||||
.arg("-c")
|
||||
.arg(command)
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.check()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user