Add logging (fix #8)
This commit is contained in:
140
Cargo.lock
generated
140
Cargo.lock
generated
@@ -1,3 +1,11 @@
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
@@ -74,6 +82,18 @@ dependencies = [
|
||||
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.5.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.1"
|
||||
@@ -93,11 +113,40 @@ dependencies = [
|
||||
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.6"
|
||||
@@ -106,6 +155,11 @@ dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.3.15"
|
||||
@@ -132,6 +186,26 @@ dependencies = [
|
||||
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.8"
|
||||
@@ -199,6 +273,14 @@ dependencies = [
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.1"
|
||||
@@ -217,6 +299,15 @@ dependencies = [
|
||||
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.4.6"
|
||||
@@ -231,8 +322,10 @@ version = "0.7.0"
|
||||
dependencies = [
|
||||
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -241,6 +334,11 @@ dependencies = [
|
||||
"which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.5"
|
||||
@@ -256,11 +354,29 @@ name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "2.0.0"
|
||||
@@ -289,7 +405,16 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "wincolor"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
|
||||
"checksum backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbdd17cd962b570302f5297aea8648d5923e22e555c2ed2d8b2e34eca646bf6d"
|
||||
@@ -299,14 +424,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
|
||||
"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
|
||||
"checksum directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc2561db021b6f1321d0f16b67ed28ce843ef4610dfaa432e3ffa2e8a3050ebf"
|
||||
"checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a"
|
||||
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
|
||||
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
|
||||
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
|
||||
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
||||
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
|
||||
"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
|
||||
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
||||
"checksum proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "effdb53b25cdad54f8f48843d67398f7ef2e14f12c1b4cb4effc549a6462a4d6"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
|
||||
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
|
||||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
|
||||
"checksum regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05b06a75f5217880fc5e905952a42750bf44787e56a6c6d6852ed0992f5e1d54"
|
||||
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
|
||||
"checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95"
|
||||
"checksum serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "0a90213fa7e0f5eac3f7afe2d5ff6b088af515052cc7303bd68c7e3b91a3fb79"
|
||||
@@ -316,14 +449,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c67da57e61ebc7b7b6fff56bb34440ca3a83db037320b0507af4c10368deda7d"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
|
||||
"checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
|
||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||
"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
|
||||
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
|
||||
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
|
||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49c4f580e93079b70ac522e7bdebbe1568c8afa7d8d05ee534ee737ca37d2f51"
|
||||
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767"
|
||||
|
||||
@@ -18,3 +18,5 @@ toml = "0.4.6"
|
||||
which = "2.0.0"
|
||||
shellexpand = "1.0.0"
|
||||
clap = "2.31.2"
|
||||
log = "0.4.2"
|
||||
env_logger = "0.5.10"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use super::utils::Check;
|
||||
use super::utils::{which, Check};
|
||||
use failure::Error;
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use which::which;
|
||||
|
||||
pub struct Git {
|
||||
git: Option<PathBuf>,
|
||||
@@ -16,9 +15,7 @@ pub struct Repositories<'a> {
|
||||
|
||||
impl Git {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
git: which("git").ok(),
|
||||
}
|
||||
Self { git: which("git") }
|
||||
}
|
||||
|
||||
pub fn get_repo_root<P: AsRef<Path>>(&self, path: P) -> Option<String> {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use super::terminal::Terminal;
|
||||
use super::utils::Check;
|
||||
use super::utils::{which, Check};
|
||||
use failure;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use which::which;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Distribution {
|
||||
@@ -55,8 +54,8 @@ pub fn upgrade_arch_linux(
|
||||
sudo: &Option<PathBuf>,
|
||||
terminal: &Terminal,
|
||||
) -> Result<(), failure::Error> {
|
||||
if let Ok(yay) = which("yay") {
|
||||
if let Ok(python) = which("python") {
|
||||
if let Some(yay) = which("yay") {
|
||||
if let Some(python) = which("python") {
|
||||
if python != PathBuf::from("/usr/bin/python") {
|
||||
terminal.print_warning(format!(
|
||||
"Python detected at {:?}, which is probably not the system Python.
|
||||
|
||||
29
src/main.rs
29
src/main.rs
@@ -11,6 +11,9 @@ extern crate serde_derive;
|
||||
extern crate clap;
|
||||
extern crate serde;
|
||||
extern crate shellexpand;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
mod config;
|
||||
mod git;
|
||||
@@ -33,7 +36,6 @@ use std::process::exit;
|
||||
use steps::*;
|
||||
use terminal::Terminal;
|
||||
use utils::{home_path, is_ancestor};
|
||||
use which::which;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display = "A step failed")]
|
||||
@@ -56,6 +58,7 @@ fn run() -> Result<(), Error> {
|
||||
.about("Upgrade all the things")
|
||||
.get_matches();
|
||||
|
||||
env_logger::init();
|
||||
let git = Git::new();
|
||||
let mut git_repos = Repositories::new(&git);
|
||||
let terminal = Terminal::new();
|
||||
@@ -63,7 +66,7 @@ fn run() -> Result<(), Error> {
|
||||
let config = Config::read()?;
|
||||
|
||||
let sudo = if cfg!(target_os = "linux") {
|
||||
which("sudo").ok()
|
||||
utils::which("sudo")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -89,7 +92,7 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos") {
|
||||
if let Ok(brew) = which("brew") {
|
||||
if let Some(brew) = utils::which("brew") {
|
||||
terminal.print_separator("Homebrew");
|
||||
run_homebrew(&brew).report("Homebrew", &mut reports);
|
||||
}
|
||||
@@ -118,7 +121,7 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
if cfg!(unix) {
|
||||
if let Ok(zsh) = which("zsh") {
|
||||
if let Some(zsh) = utils::which("zsh") {
|
||||
if home_path(".zplug").exists() {
|
||||
terminal.print_separator("zplug");
|
||||
run_zplug(&zsh).report("zplug", &mut reports);
|
||||
@@ -131,7 +134,7 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(rustup) = which("rustup") {
|
||||
if let Some(rustup) = utils::which("rustup") {
|
||||
terminal.print_separator("rustup");
|
||||
run_rustup(&rustup).report("rustup", &mut reports);
|
||||
}
|
||||
@@ -142,7 +145,7 @@ fn run() -> Result<(), Error> {
|
||||
run_cargo_update(&cargo_upgrade).report("Cargo", &mut reports);
|
||||
}
|
||||
|
||||
if let Ok(emacs) = which("emacs") {
|
||||
if let Some(emacs) = utils::which("emacs") {
|
||||
let init_file = home_path(".emacs.d/init.el");
|
||||
if init_file.exists() {
|
||||
terminal.print_separator("Emacs");
|
||||
@@ -150,7 +153,7 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(vim) = which("vim") {
|
||||
if let Some(vim) = utils::which("vim") {
|
||||
if let Some(vimrc) = vim::vimrc() {
|
||||
if let Some(plugin_framework) = vim::PluginFramework::detect(&vimrc) {
|
||||
terminal.print_separator(&format!("vim ({:?})", plugin_framework));
|
||||
@@ -160,7 +163,7 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(npm) = which("npm").map(npm::NPM::new) {
|
||||
if let Some(npm) = utils::which("npm").map(npm::NPM::new) {
|
||||
if let Ok(npm_root) = npm.root() {
|
||||
if is_ancestor(&home_dir().unwrap(), &npm_root) {
|
||||
terminal.print_separator("Node Package Manager");
|
||||
@@ -169,19 +172,19 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(apm) = which("apm") {
|
||||
if let Some(apm) = utils::which("apm") {
|
||||
terminal.print_separator("Atom Package Manager");
|
||||
run_apm(&apm).report("Atom Package Manager", &mut reports);
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
if let Ok(flatpak) = which("flatpak") {
|
||||
if let Some(flatpak) = utils::which("flatpak") {
|
||||
terminal.print_separator("Flatpak");
|
||||
run_flatpak(&flatpak).report("Flatpak", &mut reports);
|
||||
}
|
||||
|
||||
if let Some(sudo) = &sudo {
|
||||
if let Ok(snap) = which("snap") {
|
||||
if let Some(snap) = utils::which("snap") {
|
||||
terminal.print_separator("snap");
|
||||
run_snap(&sudo, &snap).report("snap", &mut reports);
|
||||
}
|
||||
@@ -196,13 +199,13 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
if let Ok(fwupdmgr) = which("fwupdmgr") {
|
||||
if let Some(fwupdmgr) = utils::which("fwupdmgr") {
|
||||
terminal.print_separator("Firmware upgrades");
|
||||
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
||||
}
|
||||
|
||||
if let Some(sudo) = &sudo {
|
||||
if let Ok(_) = which("needrestart") {
|
||||
if let Some(_) = utils::which("needrestart") {
|
||||
terminal.print_separator("Check for needed restarts");
|
||||
run_needrestart(&sudo).report("Restarts", &mut reports);
|
||||
}
|
||||
|
||||
24
src/utils.rs
24
src/utils.rs
@@ -1,7 +1,10 @@
|
||||
use failure::Error;
|
||||
use std::env::home_dir;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt::Debug;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitStatus;
|
||||
use which as which_mod;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display = "Process failed")]
|
||||
@@ -39,3 +42,24 @@ pub fn is_ancestor(ancestor: &Path, path: &Path) -> bool {
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn which<T: AsRef<OsStr> + Debug>(binary_name: T) -> Option<PathBuf> {
|
||||
match which_mod::which(&binary_name) {
|
||||
Ok(path) => {
|
||||
debug!("Detected {:?} as {:?}", &path, &binary_name);
|
||||
Some(path)
|
||||
}
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
which_mod::ErrorKind::CannotFindBinaryPath => {
|
||||
debug!("Cannot find {:?}", &binary_name);
|
||||
}
|
||||
_ => {
|
||||
error!("Detecting {:?} failed: {}", &binary_name, e);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user