Use #[cfg] instead of if cfg!
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -18,6 +18,7 @@ extern crate termcolor;
|
||||
|
||||
mod config;
|
||||
mod git;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux;
|
||||
mod npm;
|
||||
mod report;
|
||||
@@ -35,8 +36,10 @@ use std::env;
|
||||
use std::env::home_dir;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::CommandExt;
|
||||
#[cfg(unix)]
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
#[cfg(unix)]
|
||||
use std::process::Command;
|
||||
use steps::*;
|
||||
use terminal::Terminal;
|
||||
@@ -70,7 +73,8 @@ fn run() -> Result<(), Error> {
|
||||
.get_matches();
|
||||
|
||||
if matches.is_present("tmux") && !env::var("TMUX").is_ok() {
|
||||
if cfg!(unix) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let tmux = utils::which("tmux").expect("Could not find tmux");
|
||||
let err = Command::new(tmux)
|
||||
.args(&[
|
||||
@@ -87,8 +91,6 @@ fn run() -> Result<(), Error> {
|
||||
])
|
||||
.exec();
|
||||
panic!("{:?}", err);
|
||||
} else {
|
||||
panic!("This flag is only implemented in Unix systems");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,11 +101,8 @@ fn run() -> Result<(), Error> {
|
||||
let config = Config::read()?;
|
||||
let mut reports = Report::new();
|
||||
|
||||
let sudo = if cfg!(target_os = "linux") {
|
||||
utils::which("sudo")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
#[cfg(target_os = "linux")]
|
||||
let sudo = utils::which("sudo");
|
||||
|
||||
if let Some(commands) = config.pre_commands() {
|
||||
for (name, command) in commands {
|
||||
@@ -112,7 +111,8 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
terminal.print_separator("System update");
|
||||
match linux::Distribution::detect() {
|
||||
Ok(distribution) => {
|
||||
@@ -139,7 +139,8 @@ fn run() -> Result<(), Error> {
|
||||
|
||||
git_repos.insert(home_path(".emacs.d"));
|
||||
|
||||
if cfg!(unix) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
git_repos.insert(home_path(".zshrc"));
|
||||
git_repos.insert(home_path(".oh-my-zsh"));
|
||||
git_repos.insert(home_path(".tmux"));
|
||||
@@ -159,7 +160,8 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(unix) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if let Some(zsh) = utils::which("zsh") {
|
||||
if home_path(".zplug").exists() {
|
||||
terminal.print_separator("zplug");
|
||||
@@ -216,7 +218,8 @@ fn run() -> Result<(), Error> {
|
||||
run_apm(&apm).report("Atom Package Manager", &mut reports);
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if let Some(flatpak) = utils::which("flatpak") {
|
||||
terminal.print_separator("Flatpak");
|
||||
run_flatpak(&flatpak).report("Flatpak", &mut reports);
|
||||
@@ -237,7 +240,8 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if let Some(fwupdmgr) = utils::which("fwupdmgr") {
|
||||
terminal.print_separator("Firmware upgrades");
|
||||
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
||||
@@ -251,7 +255,8 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos") {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
terminal.print_separator("App Store");
|
||||
upgrade_macos().report("App Store", &mut reports);;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use utils::is_ancestor;
|
||||
|
||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn run_zplug(zsh: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(zsh)
|
||||
.args(&["-c", "source ~/.zshrc && zplug update"])
|
||||
@@ -17,6 +18,7 @@ pub fn run_zplug(zsh: &PathBuf) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn run_tpm(tpm: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(&tpm).arg("all").spawn()?.wait()?.check()?;
|
||||
|
||||
@@ -86,6 +88,7 @@ pub fn run_apm(apm: &PathBuf) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn run_needrestart(sudo: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(&sudo)
|
||||
.arg("needrestart")
|
||||
@@ -96,6 +99,7 @@ pub fn run_needrestart(sudo: &PathBuf) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn run_fwupdmgr(fwupdmgr: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(&fwupdmgr)
|
||||
.arg("refresh")
|
||||
@@ -126,6 +130,7 @@ pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn upgrade_macos() -> Result<(), failure::Error> {
|
||||
Command::new("softwareupdate")
|
||||
.args(&["--install", "--all"])
|
||||
@@ -163,6 +168,7 @@ pub fn run_custom_command(command: &str) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn run_flatpak(flatpak: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(&flatpak)
|
||||
.arg("update")
|
||||
@@ -173,6 +179,7 @@ pub fn run_flatpak(flatpak: &PathBuf) -> Result<(), failure::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn run_snap(sudo: &PathBuf, snap: &PathBuf) -> Result<(), failure::Error> {
|
||||
Command::new(&sudo)
|
||||
.args(&[snap.to_str().unwrap(), "refresh"])
|
||||
|
||||
@@ -38,6 +38,7 @@ impl Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn print_warning<P: AsRef<str>>(&mut self, message: P) {
|
||||
let message = message.as_ref();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user