Fix clippy warnings

This commit is contained in:
Roey Darwish Dror
2018-07-10 07:29:41 +03:00
parent 42fa378cf7
commit 84b8f3b236
4 changed files with 16 additions and 19 deletions

View File

@@ -64,16 +64,14 @@ It's dangerous to run yay since Python based AUR packages will be installed in t
} }
Command::new(yay).spawn()?.wait()?.check()?; Command::new(yay).spawn()?.wait()?.check()?;
} else if let Some(sudo) = &sudo {
Command::new(&sudo)
.args(&["/usr/bin/pacman", "-Syu"])
.spawn()?
.wait()?
.check()?;
} else { } else {
if let Some(sudo) = &sudo { terminal.print_warning("No sudo or yay detected. Skipping system upgrade");
Command::new(&sudo)
.args(&["/usr/bin/pacman", "-Syu"])
.spawn()?
.wait()?
.check()?;
} else {
terminal.print_warning("No sudo or yay detected. Skipping system upgrade");
}
} }
Ok(()) Ok(())

View File

@@ -53,6 +53,7 @@ struct StepFailed;
#[fail(display = "Cannot find the user base directories")] #[fail(display = "Cannot find the user base directories")]
struct NoBaseDirectories; struct NoBaseDirectories;
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
fn run() -> Result<(), Error> { fn run() -> Result<(), Error> {
let matches = App::new("Topgrade") let matches = App::new("Topgrade")
.version(crate_version!()) .version(crate_version!())
@@ -65,7 +66,7 @@ fn run() -> Result<(), Error> {
) )
.get_matches(); .get_matches();
if matches.is_present("tmux") && !env::var("TMUX").is_ok() { if matches.is_present("tmux") && env::var("TMUX").is_err() {
#[cfg(unix)] #[cfg(unix)]
{ {
unix::run_in_tmux(); unix::run_in_tmux();
@@ -144,9 +145,7 @@ fn run() -> Result<(), Error> {
for repo in git_repos.repositories() { for repo in git_repos.repositories() {
terminal.print_separator(format!("Pulling {}", repo)); terminal.print_separator(format!("Pulling {}", repo));
if let Some(success) = git.pull(&repo).ok().and_then(|i| i) { git.pull(&repo).report(format!("git: {}", repo), &mut reports);
success.report(format!("git: {}", repo), &mut reports);
}
} }
#[cfg(unix)] #[cfg(unix)]

View File

@@ -44,7 +44,7 @@ pub fn run_vim(vim: &PathBuf, vimrc: &PathBuf, upgrade_command: &str) -> Result<
.wait()? .wait()?
.check()?; .check()?;
println!(""); println!();
Ok(()) Ok(())
} }

View File

@@ -22,9 +22,9 @@ impl Terminal {
Some(width) => { Some(width) => {
let _ = self.stdout let _ = self.stdout
.set_color(ColorSpec::new().set_fg(Some(Color::White)).set_bold(true)); .set_color(ColorSpec::new().set_fg(Some(Color::White)).set_bold(true));
let _ = write!( let _ = writeln!(
&mut self.stdout, &mut self.stdout,
"\n―― {} {:―^border$}\n", "\n―― {} {:―^border$}",
message, message,
"", "",
border = max(2, min(80, width as usize) - 3 - message.len()) border = max(2, min(80, width as usize) - 3 - message.len())
@@ -33,7 +33,7 @@ impl Terminal {
let _ = self.stdout.flush(); let _ = self.stdout.flush();
} }
None => { None => {
let _ = write!(&mut self.stdout, "―― {} ――\n", message); let _ = writeln!(&mut self.stdout, "―― {} ――", message);
} }
} }
} }
@@ -44,7 +44,7 @@ impl Terminal {
let _ = self.stdout let _ = self.stdout
.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true)); .set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true));
let _ = write!(&mut self.stdout, "{}\n", message); let _ = writeln!(&mut self.stdout, "{}", message);
let _ = self.stdout.reset(); let _ = self.stdout.reset();
let _ = self.stdout.flush(); let _ = self.stdout.flush();
} }
@@ -59,7 +59,7 @@ impl Terminal {
.set_bold(true), .set_bold(true),
); );
let _ = write!(&mut self.stdout, "{}\n", if succeeded { "OK" } else { "FAILED" }); let _ = writeln!(&mut self.stdout, "{}", if succeeded { "OK" } else { "FAILED" });
let _ = self.stdout.reset(); let _ = self.stdout.reset();
let _ = self.stdout.flush(); let _ = self.stdout.flush();