Skip to content

Commit e9db963

Browse files
chore: fix clippy errors and bump version to 1.2.0
- Remove redundant imports (shellexpand, dirs) - Collapse nested if statements for better readability - Replace .get(0) with .first() - Remove unnecessary borrows in args() - Use flatten() instead of manual if let pattern
1 parent a070c8b commit e9db963

File tree

6 files changed

+26
-33
lines changed

6 files changed

+26
-33
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tide"
3-
version = "1.1.0"
3+
version = "1.2.0"
44
edition = "2021"
55
authors = ["Markus Sommer"]
66
description = "🌊 Tide - Refresh your system with the update wave"

src/executor.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use anyhow::{Context, Result};
22
use colored::Colorize;
33
use dialoguer::{theme::ColorfulTheme, Confirm, Password};
44
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
5-
use shellexpand;
65
use std::path::Path;
76
use std::process::{Command, Stdio};
87
use std::sync::Arc;
@@ -124,18 +123,17 @@ impl TaskExecutor {
124123
}
125124

126125
// Optionally save password into keychain
127-
if !keychain::entry_exists(keychain_label) {
128-
if Confirm::with_theme(&ColorfulTheme::default())
126+
if !keychain::entry_exists(keychain_label)
127+
&& Confirm::with_theme(&ColorfulTheme::default())
129128
.with_prompt("Save password to keychain for future use?")
130129
.default(true)
131130
.interact()?
132-
{
133-
keychain::save_password(keychain_label, &password)?;
134-
println!(
135-
"{}",
136-
"✓ Password saved to keychain (service: tide-sudo)".green()
137-
);
138-
}
131+
{
132+
keychain::save_password(keychain_label, &password)?;
133+
println!(
134+
"{}",
135+
"✓ Password saved to keychain (service: tide-sudo)".green()
136+
);
139137
}
140138

141139
Ok(())
@@ -253,7 +251,7 @@ impl TaskExecutor {
253251
}
254252

255253
// Execute command
256-
let result = if cmd.get(0).map(|s| s.as_str()) == Some("sudo") {
254+
let result = if cmd.first().map(|s| s.as_str()) == Some("sudo") {
257255
self.run_sudo_command(&cmd[1..], keychain_label).await
258256
} else {
259257
self.run_command(&cmd, &task, &task_name, &group_name).await
@@ -412,14 +410,13 @@ impl TaskExecutor {
412410
}
413411

414412
// 4. Optionally save password into keychain
415-
if !keychain::entry_exists(keychain_label) {
416-
if Confirm::with_theme(&ColorfulTheme::default())
413+
if !keychain::entry_exists(keychain_label)
414+
&& Confirm::with_theme(&ColorfulTheme::default())
417415
.with_prompt("Save password to keychain for future use?")
418416
.default(true)
419417
.interact()?
420-
{
421-
keychain::save_password(keychain_label, &password)?;
422-
}
418+
{
419+
keychain::save_password(keychain_label, &password)?;
423420
}
424421

425422
run_actual(args)

src/keychain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::process::{Command, Stdio};
44
/// Check if a keychain entry exists
55
pub fn entry_exists(label: &str) -> bool {
66
Command::new("security")
7-
.args(&["find-generic-password", "-s", label, "-a", "root"])
7+
.args(["find-generic-password", "-s", label, "-a", "root"])
88
.stdout(Stdio::null())
99
.stderr(Stdio::null())
1010
.status()
@@ -15,7 +15,7 @@ pub fn entry_exists(label: &str) -> bool {
1515
/// Get password from keychain
1616
pub fn get_password(label: &str) -> Result<String> {
1717
let output = Command::new("security")
18-
.args(&["find-generic-password", "-s", label, "-a", "root", "-w"])
18+
.args(["find-generic-password", "-s", label, "-a", "root", "-w"])
1919
.output()?;
2020

2121
if output.status.success() {
@@ -28,7 +28,7 @@ pub fn get_password(label: &str) -> Result<String> {
2828
/// Save password to keychain
2929
pub fn save_password(label: &str, password: &str) -> Result<()> {
3030
let status = Command::new("security")
31-
.args(&[
31+
.args([
3232
"add-generic-password",
3333
"-s",
3434
label,

src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use anyhow::Result;
1010
use clap::Parser;
1111
use colored::Colorize;
1212
use dialoguer::{theme::ColorfulTheme, Confirm};
13-
use dirs;
1413
use futures::future::join_all;
1514
use std::fs;
1615
use std::path::{Path, PathBuf};
@@ -203,10 +202,8 @@ async fn main() -> Result<()> {
203202
}
204203

205204
let parallel_results = join_all(handles).await;
206-
for result in parallel_results {
207-
if let Ok(task_result) = result {
208-
results.push(task_result);
209-
}
205+
for task_result in parallel_results.into_iter().flatten() {
206+
results.push(task_result);
210207
}
211208
}
212209

@@ -265,14 +262,13 @@ fn init_config(path: Option<&PathBuf>) -> Result<()> {
265262
fs::create_dir_all(&config_dir)?;
266263
let config_path = config_dir.join("config.toml");
267264

268-
if config_path.exists() {
269-
if !Confirm::with_theme(&ColorfulTheme::default())
265+
if config_path.exists()
266+
&& !Confirm::with_theme(&ColorfulTheme::default())
270267
.with_prompt("Config file already exists. Overwrite?")
271268
.default(false)
272269
.interact()?
273-
{
274-
return Ok(());
275-
}
270+
{
271+
return Ok(());
276272
}
277273

278274
let default_config = Config::default();

src/ui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn display_system_info() -> Result<()> {
3434
println!("{}", "─".repeat(DIVIDER_WIDTH).dimmed());
3535

3636
// Disk space
37-
if let Ok(output) = Command::new("df").args(&["-h", "/"]).output() {
37+
if let Ok(output) = Command::new("df").args(["-h", "/"]).output() {
3838
if output.status.success() {
3939
let lines = String::from_utf8_lossy(&output.stdout);
4040
if let Some(line) = lines.lines().nth(1) {
@@ -52,7 +52,7 @@ pub fn display_system_info() -> Result<()> {
5252
}
5353

5454
// Battery status
55-
if let Ok(output) = Command::new("pmset").args(&["-g", "batt"]).output() {
55+
if let Ok(output) = Command::new("pmset").args(["-g", "batt"]).output() {
5656
if output.status.success() {
5757
let info = String::from_utf8_lossy(&output.stdout);
5858
if let Some(line) = info.lines().nth(1) {

0 commit comments

Comments
 (0)