Skip to content

Commit d16d550

Browse files
committed
clippy
1 parent 33dd5e2 commit d16d550

File tree

15 files changed

+84
-91
lines changed

15 files changed

+84
-91
lines changed

src/config/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn read_config() -> Result<Config, AppError> {
5252
.ok_or(AppError::InternalError("Failed to get project name"))?;
5353
project.project_config_path = PathBuf::from(project_file.path().parent().ok_or(AppError::InternalError("Expected file to have a parent"))?)
5454
.strip_prefix(paths.projects.as_path())
55-
.map_err(|e| AppError::RuntimeError(format!("Failed to strip prefix: {}", e)))?
55+
.map_err(|e| AppError::RuntimeError(format!("Failed to strip prefix: {e}")))?
5656
.to_string_lossy()
5757
.to_string();
5858
if projects.contains_key(&project.name) {
@@ -81,13 +81,12 @@ pub fn read_config() -> Result<Config, AppError> {
8181
.ok_or(AppError::InternalError("Failed to get tag name"))?;
8282
tag.tag_config_path = PathBuf::from(tag_file.path().parent().ok_or(AppError::InternalError("Expected file to have a parent"))?)
8383
.strip_prefix(paths.tags.as_path())
84-
.map_err(|e| AppError::RuntimeError(format!("Failed to strip prefix: {}", e)))?
84+
.map_err(|e| AppError::RuntimeError(format!("Failed to strip prefix: {e}")))?
8585
.to_string_lossy()
8686
.to_string();
8787
if tags.contains_key(&tag_name) {
8888
eprintln!(
89-
"Inconsistency found: tag {} defined more than once. Will use the project that is found last. Results might be inconsistent.",
90-
tag_name
89+
"Inconsistency found: tag {tag_name} defined more than once. Will use the project that is found last. Results might be inconsistent."
9190
);
9291
}
9392
tags.insert(tag_name, tag);
@@ -121,7 +120,7 @@ pub fn write_settings(settings: &PersistedSettings) -> Result<(), AppError> {
121120

122121
let mut buffer = File::create(&paths.settings)?;
123122
let serialized = toml::to_string_pretty(settings)?;
124-
write!(buffer, "{}", serialized)?;
123+
write!(buffer, "{serialized}")?;
125124
write_example(&mut buffer, PersistedSettings::example())?;
126125

127126
Ok(())
@@ -142,8 +141,8 @@ pub fn write_tag(tag_name: &str, tag: &Tag) -> Result<(), AppError> {
142141
let mut buffer = File::create(&tag_file_path)
143142
.map_err(|e| AppError::RuntimeError(format!("Failed to create project config file '{}'. {}", tag_file_path.to_string_lossy(), e)))?;
144143
let serialized = toml::to_string_pretty(&tag)?;
145-
write!(buffer, "{}", CONF_MODE_HEADER)?;
146-
write!(buffer, "{}", serialized)?;
144+
write!(buffer, "{CONF_MODE_HEADER}")?;
145+
write!(buffer, "{serialized}")?;
147146
write_example(&mut buffer, Tag::example())?;
148147
Ok(())
149148
}
@@ -156,7 +155,7 @@ pub fn delete_tag_config(tag_name: &str, tag: &Tag) -> Result<(), AppError> {
156155
tag_file_path.push(PathBuf::from(&tag.tag_config_path));
157156
tag_file_path.push(tag_name);
158157

159-
fs::remove_file(&tag_file_path).map_err(|e| AppError::RuntimeError(format!("Failed to delete tag config from '{:?}': {}", tag_file_path, e)))?;
158+
fs::remove_file(&tag_file_path).map_err(|e| AppError::RuntimeError(format!("Failed to delete tag config from '{tag_file_path:?}': {e}")))?;
160159
Ok(())
161160
}
162161

@@ -168,7 +167,7 @@ pub fn delete_project_config(project: &Project) -> Result<(), AppError> {
168167
project_file_path.push(PathBuf::from(&project.project_config_path));
169168
project_file_path.push(&project.name);
170169

171-
fs::remove_file(project_file_path).map_err(|e| AppError::RuntimeError(format!("Failed to delete project config: {}", e)))?;
170+
fs::remove_file(project_file_path).map_err(|e| AppError::RuntimeError(format!("Failed to delete project config: {e}")))?;
172171
Ok(())
173172
}
174173

@@ -180,7 +179,7 @@ where
180179
writeln!(buffer, "\n# Example:")?;
181180
for line in example_toml.split('\n') {
182181
if line.trim() != "" {
183-
writeln!(buffer, "# {}", line)?;
182+
writeln!(buffer, "# {line}")?;
184183
}
185184
}
186185
Ok(())
@@ -202,8 +201,8 @@ pub fn write_project(project: &Project) -> Result<(), AppError> {
202201
.map_err(|e| AppError::RuntimeError(format!("Failed to create project config file '{}'. {}", project_file_path.to_string_lossy(), e)))?;
203202
let serialized = toml::to_string_pretty(&project)?;
204203

205-
write!(buffer, "{}", CONF_MODE_HEADER)?;
206-
write!(buffer, "{}", serialized)?;
204+
write!(buffer, "{CONF_MODE_HEADER}")?;
205+
write!(buffer, "{serialized}")?;
207206
write_example(&mut buffer, Project::example())?;
208207
Ok(())
209208
}

src/config/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct FwPaths {
1212

1313
impl FwPaths {
1414
pub fn ensure_base_exists(&self) -> Result<(), AppError> {
15-
std::fs::create_dir_all(&self.base).map_err(|e| AppError::RuntimeError(format!("Failed to create fw config base directory. {}", e)))?;
15+
std::fs::create_dir_all(&self.base).map_err(|e| AppError::RuntimeError(format!("Failed to create fw config base directory. {e}")))?;
1616
Ok(())
1717
}
1818
}
@@ -46,11 +46,11 @@ pub fn fw_path() -> Result<FwPaths, AppError> {
4646

4747
let env: String = env::var_os("FW_ENV")
4848
.map(|s| s.to_string_lossy().to_string())
49-
.map(|s| format!("{}_", s))
49+
.map(|s| format!("{s}_"))
5050
.unwrap_or_default()
5151
.replace('/', "");
5252

53-
settings.push(format!("{}settings.toml", env));
53+
settings.push(format!("{env}settings.toml"));
5454

5555
let mut projects = base.clone();
5656
projects.push("projects");

src/errors/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ impl AppError {
4040
impl fmt::Display for AppError {
4141
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4242
match *self {
43-
AppError::Io(ref err) => write!(f, "Io error: {}", err),
44-
AppError::UserError(ref str) => write!(f, "User error: {}", str),
45-
AppError::RuntimeError(ref str) => write!(f, "Runtime error: {}", str),
46-
AppError::BadJson(ref err) => write!(f, "JSON error: {}", err),
47-
AppError::InternalError(str) => write!(f, "Internal error: {}", str),
48-
AppError::GitError(ref err) => write!(f, "Git error: {}", err),
49-
AppError::Regex(ref err) => write!(f, "Regex error: {}", err),
50-
AppError::TomlSerError(ref err) => write!(f, "toml serialization error: {}", err),
51-
AppError::TomlDeError(ref err) => write!(f, "toml read error: {}", err),
52-
AppError::WalkdirError(ref err) => write!(f, "walkdir error: {}", err),
53-
AppError::ReqwestError(ref err) => write!(f, "reqwest error: {}", err),
43+
AppError::Io(ref err) => write!(f, "Io error: {err}"),
44+
AppError::UserError(ref str) => write!(f, "User error: {str}"),
45+
AppError::RuntimeError(ref str) => write!(f, "Runtime error: {str}"),
46+
AppError::BadJson(ref err) => write!(f, "JSON error: {err}"),
47+
AppError::InternalError(str) => write!(f, "Internal error: {str}"),
48+
AppError::GitError(ref err) => write!(f, "Git error: {err}"),
49+
AppError::Regex(ref err) => write!(f, "Regex error: {err}"),
50+
AppError::TomlSerError(ref err) => write!(f, "toml serialization error: {err}"),
51+
AppError::TomlDeError(ref err) => write!(f, "toml read error: {err}"),
52+
AppError::WalkdirError(ref err) => write!(f, "walkdir error: {err}"),
53+
AppError::ReqwestError(ref err) => write!(f, "reqwest error: {err}"),
5454
}
5555
}
5656
}
@@ -73,7 +73,7 @@ impl Error for AppError {
7373

7474
impl From<core::num::ParseIntError> for AppError {
7575
fn from(err: core::num::ParseIntError) -> AppError {
76-
AppError::UserError(format!("Type error: {}", err))
76+
AppError::UserError(format!("Type error: {err}"))
7777
}
7878
}
7979

src/git/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use std::path::Path;
1414
pub fn repo_name_from_url(url: &str) -> Result<&str, AppError> {
1515
let last_fragment = url.rsplit('/').next().ok_or_else(|| {
1616
AppError::UserError(format!(
17-
"Given URL {} does not have path fragments so cannot determine project name. Please give \
18-
one.",
19-
url
17+
"Given URL {url} does not have path fragments so cannot determine project name. Please give \
18+
one."
2019
))
2120
})?;
2221

@@ -127,7 +126,7 @@ pub fn clone_project(config: &Config, project: &Project, path: &Path) -> Result<
127126
let after_clone = config.resolve_after_clone(project);
128127
if !after_clone.is_empty() {
129128
spawn_maybe(&shell, &after_clone.join(" && "), path, &project.name, random_color())
130-
.map_err(|error| AppError::UserError(format!("Post-clone hook failed (nonzero exit code). Cause: {:?}", error)))
129+
.map_err(|error| AppError::UserError(format!("Post-clone hook failed (nonzero exit code). Cause: {error:?}")))
131130
} else {
132131
Ok(())
133132
}

src/intellij/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn get_recent_projects_candidates() -> Result<Vec<PathBuf>, AppError> {
5757
}
5858

5959
fn print_number_of_projects_warning(number_of_projects: usize) {
60-
print!("WARNING: {} ", number_of_projects);
60+
print!("WARNING: {number_of_projects} ");
6161
print!("projects were added to the list. Intellij only lists 50 projects by default. You can change this in Intellij by going to ");
6262
print!(r#"Settings -> Search for "recent" -> Pick the "Advanced Settings" -> adjust "Maximum number of recent projects"."#);
6363
println!("A high number is recommended since it won't do any harm to the system.");

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ fn _main() -> i32 {
1515
let config = config::read_config();
1616
if config.is_err() {
1717
eprintln!(
18-
"Could not read v2.0 config: {:?}. If you are running the setup right now this is expected.",
19-
config
18+
"Could not read v2.0 config: {config:?}. If you are running the setup right now this is expected."
2019
);
2120
};
2221

@@ -144,7 +143,7 @@ fn _main() -> i32 {
144143
match result {
145144
Ok(()) => 0,
146145
Err(error) => {
147-
eprintln!("Error running command: error {}", error);
146+
eprintln!("Error running command: error {error}");
148147
1
149148
}
150149
}

src/project/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ pub fn add_entry(
1818
trusted: bool,
1919
) -> Result<(), AppError> {
2020
let name = maybe_name
21-
.ok_or_else(|| AppError::UserError(format!("No project name specified for {}", url)))
21+
.ok_or_else(|| AppError::UserError(format!("No project name specified for {url}")))
2222
.or_else(|_| repo_name_from_url(url).map(ToOwned::to_owned))?;
2323
let config: Config = maybe_config?;
2424
if config.projects.contains_key(&name) {
2525
Err(AppError::UserError(format!(
26-
"Project key {} already exists, not gonna overwrite it for you",
27-
name
26+
"Project key {name} already exists, not gonna overwrite it for you"
2827
)))
2928
} else {
3029
let default_after_clone = config.settings.default_after_clone.clone();
@@ -56,7 +55,7 @@ pub fn remove_project(maybe_config: Result<Config, AppError>, project_name: &str
5655
let config: Config = maybe_config?;
5756

5857
if !config.projects.contains_key(project_name) {
59-
Err(AppError::UserError(format!("Project key {} does not exist in config", project_name)))
58+
Err(AppError::UserError(format!("Project key {project_name} does not exist in config")))
6059
} else if let Some(project) = config.projects.get(project_name).cloned() {
6160
if purge_directory {
6261
let path = config.actual_path_to_project(&project);
@@ -67,21 +66,20 @@ pub fn remove_project(maybe_config: Result<Config, AppError>, project_name: &str
6766
}
6867
config::delete_project_config(&project)
6968
} else {
70-
Err(AppError::UserError(format!("Unknown project {}", project_name)))
69+
Err(AppError::UserError(format!("Unknown project {project_name}")))
7170
}
7271
}
7372

7473
pub fn add_remote(maybe_config: Result<Config, AppError>, name: &str, remote_name: String, git: String) -> Result<(), AppError> {
7574
let config: Config = maybe_config?;
7675
if !config.projects.contains_key(name) {
77-
return Err(AppError::UserError(format!("Project key {} does not exists. Can not update.", name)));
76+
return Err(AppError::UserError(format!("Project key {name} does not exists. Can not update.")));
7877
}
7978
let mut project_config: Project = config.projects.get(name).expect("Already checked in the if above").clone();
8079
let mut additional_remotes = project_config.additional_remotes.unwrap_or_default();
8180
if additional_remotes.iter().any(|r| r.name == remote_name) {
8281
return Err(AppError::UserError(format!(
83-
"Remote {} for project {} does already exist. Can not add.",
84-
remote_name, name
82+
"Remote {remote_name} for project {name} does already exist. Can not add."
8583
)));
8684
}
8785
additional_remotes.push(Remote { name: remote_name, git });
@@ -94,7 +92,7 @@ pub fn add_remote(maybe_config: Result<Config, AppError>, name: &str, remote_nam
9492
pub fn remove_remote(maybe_config: Result<Config, AppError>, name: &str, remote_name: String) -> Result<(), AppError> {
9593
let config: Config = maybe_config?;
9694
if !config.projects.contains_key(name) {
97-
return Err(AppError::UserError(format!("Project key {} does not exists. Can not update.", name)));
95+
return Err(AppError::UserError(format!("Project key {name} does not exists. Can not update.")));
9896
}
9997
let mut project_config: Project = config.projects.get(name).expect("Already checked in the if above").clone();
10098
let additional_remotes = project_config.additional_remotes.unwrap_or_default();
@@ -116,11 +114,10 @@ pub fn update_entry(
116114
let config: Config = maybe_config?;
117115
if name.starts_with("http") || name.starts_with("git@") {
118116
Err(AppError::UserError(format!(
119-
"{} looks like a repo URL and not like a project name, please fix",
120-
name
117+
"{name} looks like a repo URL and not like a project name, please fix"
121118
)))
122119
} else if !config.projects.contains_key(name) {
123-
Err(AppError::UserError(format!("Project key {} does not exists. Can not update.", name)))
120+
Err(AppError::UserError(format!("Project key {name} does not exists. Can not update.")))
124121
} else {
125122
let old_project_config: Project = config.projects.get(name).expect("Already checked in the if above").clone();
126123
config::write_project(&Project {
@@ -143,7 +140,7 @@ pub fn ls(maybe_config: Result<Config, AppError>, tags: &BTreeSet<String>) -> Re
143140
let config = maybe_config?;
144141
for (name, project) in config.projects {
145142
if tags.is_empty() || project.tags.unwrap_or_default().intersection(tags).count() > 0 {
146-
println!("{}", name)
143+
println!("{name}")
147144
}
148145
}
149146
Ok(())
@@ -154,12 +151,12 @@ pub fn print_path(maybe_config: Result<Config, AppError>, name: &str) -> Result<
154151
let project = config
155152
.projects
156153
.get(name)
157-
.ok_or_else(|| AppError::UserError(format!("project {} not found", name)))?;
154+
.ok_or_else(|| AppError::UserError(format!("project {name} not found")))?;
158155
let canonical_project_path = config.actual_path_to_project(project);
159156
let path = canonical_project_path
160157
.to_str()
161158
.ok_or(AppError::InternalError("project path is not valid unicode"))?;
162-
println!("{}", path);
159+
println!("{path}");
163160
Ok(())
164161
}
165162

@@ -168,7 +165,7 @@ pub fn inspect(name: &str, maybe_config: Result<Config, AppError>, json: bool) -
168165
let project = config
169166
.projects
170167
.get(name)
171-
.ok_or_else(|| AppError::UserError(format!("project {} not found", name)))?;
168+
.ok_or_else(|| AppError::UserError(format!("project {name} not found")))?;
172169
if json {
173170
println!("{}", serde_json::to_string(project)?);
174171
return Ok(());
@@ -208,7 +205,7 @@ pub(crate) fn move_project(maybe_config: Result<Config, AppError>, name: &str, d
208205
let project = config
209206
.projects
210207
.get(name)
211-
.ok_or_else(|| AppError::UserError(format!("project {} not found", name)))?;
208+
.ok_or_else(|| AppError::UserError(format!("project {name} not found")))?;
212209
let canonical_project_path = config.actual_path_to_project(project);
213210

214211
let mut path = path::absolute(destination)?;

src/projectile/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ where
2727
buffer.write_all(b"(")?;
2828
for path in paths {
2929
let path = replace_path_with_tilde(&path, home_dir.to_path_buf()).unwrap_or(path);
30-
buffer.write_all(format!("\"{}/\"", path).as_bytes())?;
30+
buffer.write_all(format!("\"{path}/\"").as_bytes())?;
3131
buffer.write_all(b" ")?;
3232
}
3333
buffer.write_all(b")")?;

src/setup/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ pub fn setup(workspace_dir: &str) -> Result<(), AppError> {
4848
let maybe_path = if path.exists() {
4949
Ok(path)
5050
} else {
51-
Err(AppError::UserError(format!("Given workspace path {} does not exist", workspace_dir)))
51+
Err(AppError::UserError(format!("Given workspace path {workspace_dir} does not exist")))
5252
};
5353

5454
maybe_path
5555
.and_then(|path| {
5656
if path.is_absolute() {
5757
Ok(path)
5858
} else {
59-
Err(AppError::UserError(format!("Workspace path {} needs to be absolute", workspace_dir)))
59+
Err(AppError::UserError(format!("Workspace path {workspace_dir} needs to be absolute")))
6060
}
6161
})
6262
.and_then(determine_projects)
@@ -80,7 +80,7 @@ fn determine_projects(path: PathBuf) -> Result<BTreeMap<String, Project>, AppErr
8080
Ok(project) => {
8181
projects.insert(project.name.clone(), project);
8282
}
83-
Err(e) => eprintln!("Error while importing folder. Skipping it. {}", e),
83+
Err(e) => eprintln!("Error while importing folder. Skipping it. {e}"),
8484
}
8585
}
8686
Err(_) => eprintln!("Failed to parse directory name as unicode. Skipping it."),
@@ -98,8 +98,7 @@ pub fn org_import(maybe_config: Result<Config, AppError>, org_name: &str, includ
9898
.or_else(|| current_config.settings.github_token.clone())
9999
.ok_or_else(|| {
100100
AppError::UserError(format!(
101-
"Can't call GitHub API for org {} because no github oauth token (settings.github_token) specified in the configuration.",
102-
org_name
101+
"Can't call GitHub API for org {org_name} because no github oauth token (settings.github_token) specified in the configuration."
103102
))
104103
})?;
105104
let mut api = github::github_api(&token)?;
@@ -112,7 +111,7 @@ pub fn org_import(maybe_config: Result<Config, AppError>, org_name: &str, includ
112111
for name in org_repository_names {
113112
let p = Project {
114113
name: name.clone(),
115-
git: format!("git@github.com:{}/{}.git", org_name, name),
114+
git: format!("git@github.com:{org_name}/{name}.git"),
116115
after_clone: after_clone.clone(),
117116
after_workon: after_workon.clone(),
118117
override_path: None,

0 commit comments

Comments
 (0)