Skip to content

Commit 669a69b

Browse files
committed
Fix all clippy warnings
Apply cargo clippy --fix for auto-fixable warnings (needless borrows, expect with format, useless vec, etc.) and manually fix remaining ones: Display trait impls, matches! macro, slice params, type alias, LTS rename.
1 parent 0080199 commit 669a69b

File tree

17 files changed

+145
-179
lines changed

17 files changed

+145
-179
lines changed

src/stage4/src/bloody_indiana_jones.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn get_file_name(url: &str) -> String {
1616
.unwrap()
1717
.path_segments()
1818
.unwrap()
19-
.last()
19+
.next_back()
2020
.unwrap()
2121
.to_string()
2222
}
@@ -89,10 +89,10 @@ impl BloodyIndianaJones {
8989
.get(&self.url)
9090
.send()
9191
.await
92-
.expect(format!("Failed to get {}", &self.url).as_str());
92+
.unwrap_or_else(|_| panic!("Failed to get {}", &self.url));
9393
let total_size = res
9494
.content_length()
95-
.expect(format!("Failed to get content length from {}", &self.url).as_str());
95+
.unwrap_or_else(|| panic!("Failed to get content length from {}", &self.url));
9696

9797
debug!("Total size {:?}", total_size);
9898

@@ -104,7 +104,7 @@ impl BloodyIndianaJones {
104104
debug!("{:?}", &self.file_path);
105105

106106
let mut file = File::create(&self.file_path)
107-
.expect(format!("Failed to create file '{}'", &self.file_path).as_str());
107+
.unwrap_or_else(|_| panic!("Failed to create file '{}'", &self.file_path));
108108
let mut downloaded: u64 = 0;
109109
let mut stream = res.bytes_stream();
110110

@@ -248,24 +248,20 @@ impl BloodyIndianaJones {
248248
if let Ok(entries) = entries {
249249
let entries = entries.collect::<Vec<_>>();
250250
if entries.len() == 1 {
251-
for entry in entries {
252-
if let Ok(entry) = entry {
253-
if entry.path().is_dir() {
254-
debug!(
255-
"Extracted files are contained in sub-folder. Moving them up"
256-
);
257-
let parent = entry.path();
258-
if let Ok(entries) = read_dir(&parent) {
259-
for entry in entries {
260-
if let Ok(entry) = entry {
261-
let path = entry.path();
262-
let new_path =
263-
parent_path.join(path.file_name().unwrap());
264-
rename(&path, new_path).unwrap();
265-
}
266-
}
267-
remove_dir(parent).ok();
251+
for entry in entries.into_iter().flatten() {
252+
if entry.path().is_dir() {
253+
debug!(
254+
"Extracted files are contained in sub-folder. Moving them up"
255+
);
256+
let parent = entry.path();
257+
if let Ok(entries) = read_dir(&parent) {
258+
for entry in entries.flatten() {
259+
let path = entry.path();
260+
let new_path =
261+
parent_path.join(path.file_name().unwrap());
262+
rename(&path, new_path).unwrap();
268263
}
264+
remove_dir(parent).ok();
269265
}
270266
}
271267
}

src/stage4/src/checker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::executor::{prep, AppInput, GgMeta};
33
use crate::updater;
44
use crate::Executor;
55
use futures_util::future::join_all;
6-
use glob;
76
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
87
use log::{debug, info};
98
use std::collections::HashMap;
@@ -206,7 +205,7 @@ pub async fn check_or_update_all(
206205
let update_infos: Vec<UpdateInfo> = join_all(check_tasks)
207206
.await
208207
.into_iter()
209-
.filter_map(|x| x)
208+
.flatten()
210209
.collect();
211210

212211
m.clear().unwrap();
@@ -226,7 +225,7 @@ pub async fn check_or_update_all(
226225
for info in &update_infos {
227226
grouped_tools
228227
.entry(info.tool_name.clone())
229-
.or_insert(Vec::new())
228+
.or_default()
230229
.push(info);
231230
}
232231

src/stage4/src/cli.rs

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -169,71 +169,69 @@ impl Cli {
169169
)
170170
}
171171
}
172-
} else {
173-
if let Some(first_arg) = self.args.first() {
174-
if let Some(alias_commands) = config.resolve_alias_with_and(first_arg) {
175-
if alias_commands.len() > 1 {
176-
return (
177-
vec![ClapCmd {
178-
cmd: format!("__multi_alias__{}", first_arg),
179-
version: None,
180-
distribution: None,
181-
include_tags: HashSet::new(),
182-
exclude_tags: HashSet::new(),
183-
gems: None,
184-
}],
185-
self.args[1..].to_vec(),
186-
);
187-
}
172+
} else if let Some(first_arg) = self.args.first() {
173+
if let Some(alias_commands) = config.resolve_alias_with_and(first_arg) {
174+
if alias_commands.len() > 1 {
175+
return (
176+
vec![ClapCmd {
177+
cmd: format!("__multi_alias__{}", first_arg),
178+
version: None,
179+
distribution: None,
180+
include_tags: HashSet::new(),
181+
exclude_tags: HashSet::new(),
182+
gems: None,
183+
}],
184+
self.args[1..].to_vec(),
185+
);
188186
}
187+
}
189188

190-
if let Some(alias_args) = config.resolve_alias(first_arg) {
191-
let mut expanded_args = alias_args;
192-
expanded_args.extend_from_slice(&self.args[1..]);
193-
194-
let mut depth = 0;
195-
const MAX_DEPTH: usize = 10;
196-
while depth < MAX_DEPTH {
197-
if let Some(first) = expanded_args.first() {
198-
if let Some(nested_alias) = config.resolve_alias(first) {
199-
let rest = expanded_args[1..].to_vec();
200-
expanded_args = nested_alias;
201-
expanded_args.extend(rest);
202-
depth += 1;
203-
continue;
204-
}
189+
if let Some(alias_args) = config.resolve_alias(first_arg) {
190+
let mut expanded_args = alias_args;
191+
expanded_args.extend_from_slice(&self.args[1..]);
192+
193+
let mut depth = 0;
194+
const MAX_DEPTH: usize = 10;
195+
while depth < MAX_DEPTH {
196+
if let Some(first) = expanded_args.first() {
197+
if let Some(nested_alias) = config.resolve_alias(first) {
198+
let rest = expanded_args[1..].to_vec();
199+
expanded_args = nested_alias;
200+
expanded_args.extend(rest);
201+
depth += 1;
202+
continue;
205203
}
206-
break;
207204
}
205+
break;
206+
}
208207

209-
let cmds = if let Some(cmd_part) = expanded_args.first() {
210-
parse_command_string(cmd_part, config)
211-
} else {
212-
vec![]
213-
};
214-
let app_args = expanded_args[1..].to_vec();
215-
(cmds, app_args)
208+
let cmds = if let Some(cmd_part) = expanded_args.first() {
209+
parse_command_string(cmd_part, config)
216210
} else {
217-
let cmds = parse_command_string(first_arg, config);
218-
let app_args = self.args[1..].to_vec();
219-
220-
if cmds.len() == 1
221-
&& cmds[0].cmd == "run"
222-
&& app_args.first().map_or(false, |a| {
223-
a.starts_with("gh/") || get_tool_info(a).is_some()
224-
})
225-
{
226-
let tool = &app_args[0];
227-
let new_cmds = parse_command_string(tool, config);
228-
let new_app_args = app_args[1..].to_vec();
229-
return (new_cmds, new_app_args);
230-
}
231-
232-
(cmds, app_args)
233-
}
211+
vec![]
212+
};
213+
let app_args = expanded_args[1..].to_vec();
214+
(cmds, app_args)
234215
} else {
235-
(vec![], vec![])
216+
let cmds = parse_command_string(first_arg, config);
217+
let app_args = self.args[1..].to_vec();
218+
219+
if cmds.len() == 1
220+
&& cmds[0].cmd == "run"
221+
&& app_args.first().is_some_and(|a| {
222+
a.starts_with("gh/") || get_tool_info(a).is_some()
223+
})
224+
{
225+
let tool = &app_args[0];
226+
let new_cmds = parse_command_string(tool, config);
227+
let new_app_args = app_args[1..].to_vec();
228+
return (new_cmds, new_app_args);
229+
}
230+
231+
(cmds, app_args)
236232
}
233+
} else {
234+
(vec![], vec![])
237235
}
238236
}
239237

src/stage4/src/config.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@ use std::fs;
66
use std::path::{Path, PathBuf};
77

88
#[derive(Debug, Clone, Serialize, Deserialize)]
9+
#[derive(Default)]
910
pub struct GgConfig {
1011
#[serde(default)]
1112
pub dependencies: HashMap<String, String>,
1213
#[serde(default)]
1314
pub aliases: HashMap<String, String>,
1415
}
1516

16-
impl Default for GgConfig {
17-
fn default() -> Self {
18-
Self {
19-
dependencies: HashMap::new(),
20-
aliases: HashMap::new(),
21-
}
22-
}
23-
}
2417

2518
impl GgConfig {
2619
pub fn load() -> Self {

0 commit comments

Comments
 (0)