Skip to content

Commit 69fd95a

Browse files
committed
clippy
Signed-off-by: Jessie Frazelle <[email protected]>
1 parent c86a1ab commit 69fd95a

File tree

15 files changed

+125
-129
lines changed

15 files changed

+125
-129
lines changed

src/cmd_alias.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl crate::cmd::Command for CmdAliasDelete {
4848

4949
let (expansion, ok) = alias_config.get(&self.alias);
5050
if !ok {
51-
bail!("no such alias {}", self.alias);
51+
let alias = &self.alias;
52+
bail!("no such alias {alias}");
5253
}
5354

5455
match alias_config.delete(&self.alias) {
@@ -63,7 +64,8 @@ impl crate::cmd::Command for CmdAliasDelete {
6364
)?;
6465
}
6566
Err(e) => {
66-
bail!("failed to delete alias {}: {}", self.alias, e);
67+
let alias = &self.alias;
68+
bail!("failed to delete alias {alias}: {e}");
6769
}
6870
}
6971

src/cmd_auth.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl crate::cmd::Command for CmdAuthLogin {
166166
return Ok(());
167167
}
168168
Err(err) => {
169-
return Err(anyhow!("prompt failed: {}", err));
169+
return Err(anyhow!("prompt failed: {err}"));
170170
}
171171
}
172172
}
@@ -189,7 +189,7 @@ impl crate::cmd::Command for CmdAuthLogin {
189189
}
190190
}
191191
Err(err) => {
192-
return Err(anyhow!("prompt failed: {}", err));
192+
return Err(anyhow!("prompt failed: {err}"));
193193
}
194194
}
195195
}
@@ -251,7 +251,7 @@ impl crate::cmd::Command for CmdAuthLogin {
251251
{
252252
Ok(input) => input,
253253
Err(err) => {
254-
return Err(anyhow!("prompt failed: {}", err));
254+
return Err(anyhow!("prompt failed: {err}"));
255255
}
256256
}
257257
};
@@ -274,7 +274,9 @@ impl crate::cmd::Command for CmdAuthLogin {
274274
// Save the config.
275275
ctx.config.write()?;
276276

277-
writeln!(ctx.io.out, "{} Logged in as {}", cs.success_icon(), cs.bold(&email))?;
277+
let success_icon = cs.success_icon();
278+
let bold_email = cs.bold(&email);
279+
writeln!(ctx.io.out, "{success_icon} Logged in as {bold_email}")?;
278280

279281
Ok(())
280282
}
@@ -319,7 +321,7 @@ impl crate::cmd::Command for CmdAuthLogout {
319321
match index {
320322
Ok(i) => candidates[i].to_string(),
321323
Err(err) => {
322-
return Err(anyhow!("prompt failed: {}", err));
324+
return Err(anyhow!("prompt failed: {err}"));
323325
}
324326
}
325327
}
@@ -334,7 +336,7 @@ impl crate::cmd::Command for CmdAuthLogout {
334336
}
335337

336338
if !found {
337-
return Err(anyhow!("not logged into {}", hostname));
339+
return Err(anyhow!("not logged into {hostname}"));
338340
}
339341

340342
hostname
@@ -368,11 +370,10 @@ impl crate::cmd::Command for CmdAuthLogout {
368370
let cs = ctx.io.color_scheme();
369371

370372
if ctx.io.can_prompt() {
373+
let bold_email = cs.bold(&email);
371374
match dialoguer::Confirm::new()
372375
.with_prompt(format!(
373-
"Are you sure you want to log out of {} as {}?",
374-
hostname,
375-
cs.bold(&email)
376+
"Are you sure you want to log out of {hostname} as {bold_email}?"
376377
))
377378
.interact()
378379
{
@@ -381,7 +382,7 @@ impl crate::cmd::Command for CmdAuthLogout {
381382
return Ok(());
382383
}
383384
Err(err) => {
384-
return Err(anyhow!("prompt failed: {}", err));
385+
return Err(anyhow!("prompt failed: {err}"));
385386
}
386387
}
387388
}
@@ -393,13 +394,9 @@ impl crate::cmd::Command for CmdAuthLogout {
393394
ctx.config.write()?;
394395

395396
let cs = ctx.io.color_scheme();
396-
writeln!(
397-
ctx.io.out,
398-
"{} Logged out of {} as {}",
399-
cs.success_icon(),
400-
hostname,
401-
cs.bold(&email)
402-
)?;
397+
let success_icon = cs.success_icon();
398+
let bold_email = cs.bold(&email);
399+
writeln!(ctx.io.out, "{success_icon} Logged out of {hostname} as {bold_email}")?;
403400

404401
Ok(())
405402
}
@@ -427,10 +424,10 @@ impl crate::cmd::Command for CmdAuthStatus {
427424
let hostnames = ctx.config.hosts()?;
428425

429426
if hostnames.is_empty() {
427+
let bold_login = cs.bold("zoo auth login");
430428
writeln!(
431429
ctx.io.out,
432-
"You are not logged into any Zoo hosts. Run `{}` to authenticate.",
433-
cs.bold("zoo auth login")
430+
"You are not logged into any Zoo hosts. Run `{bold_login}` to authenticate."
434431
)?;
435432
return Ok(());
436433
}
@@ -460,21 +457,21 @@ impl crate::cmd::Command for CmdAuthStatus {
460457
.email
461458
.ok_or_else(|| anyhow::anyhow!("user does not have an email"))?;
462459

460+
let success_icon = cs.success_icon();
461+
let bold_email = cs.bold(&email);
463462
host_status.push(format!(
464-
"{} Logged in to {} as {} ({})",
465-
cs.success_icon(),
466-
hostname,
467-
cs.bold(&email),
468-
token_source
463+
"{success_icon} Logged in to {hostname} as {bold_email} ({token_source})"
469464
));
470465
let mut token_display = "*******************".to_string();
471466
if self.show_token {
472467
token_display = token.to_string();
473468
}
474-
host_status.push(format!("{} Token: {}", cs.success_icon(), token_display));
469+
let success_icon = cs.success_icon();
470+
host_status.push(format!("{success_icon} Token: {token_display}"));
475471
}
476472
Err(err) => {
477-
host_status.push(format!("{} {}: api call failed: {}", cs.failure_icon(), hostname, err));
473+
let failure_icon = cs.failure_icon();
474+
host_status.push(format!("{failure_icon} {hostname}: api call failed: {err}"));
478475
failed = true;
479476
continue;
480477
}
@@ -484,18 +481,22 @@ impl crate::cmd::Command for CmdAuthStatus {
484481
}
485482

486483
if !hostname_found {
487-
writeln!(
488-
ctx.io.err_out,
489-
"Hostname {} not found among authenticated Zoo hosts",
490-
only_host.as_deref().unwrap_or("")
491-
)?;
484+
if let Some(only_host) = only_host {
485+
writeln!(
486+
ctx.io.err_out,
487+
"Hostname {only_host} not found among authenticated Zoo hosts"
488+
)?;
489+
} else {
490+
writeln!(ctx.io.err_out, "Requested host not found among authenticated Zoo hosts")?;
491+
}
492492
return Err(anyhow!(""));
493493
}
494494

495495
for hostname in hostnames {
496496
match status_info.get(&hostname) {
497497
Some(status) => {
498-
writeln!(ctx.io.out, "{}", cs.bold(&hostname))?;
498+
let bold_hostname = cs.bold(&hostname);
499+
writeln!(ctx.io.out, "{bold_hostname}")?;
499500
for line in status {
500501
writeln!(ctx.io.out, "{line}")?;
501502
}
@@ -598,6 +599,7 @@ mod test {
598599
let mut c = crate::config_from_env::EnvConfig::inherit_env(&mut config);
599600

600601
for t in tests {
602+
let test_name = &t.name;
601603
let (mut io, stdout_path, stderr_path) = crate::iostreams::IoStreams::test();
602604
if !t.stdin.is_empty() {
603605
io.stdin = Box::new(std::io::Cursor::new(t.stdin));
@@ -622,19 +624,19 @@ mod test {
622624
Ok(()) => {
623625
let stdout = std::fs::read_to_string(stdout_path).unwrap();
624626
let stderr = std::fs::read_to_string(stderr_path).unwrap();
625-
assert!(stderr.is_empty(), "test {}: {}", t.name, stderr);
627+
assert!(stderr.is_empty(), "test {test_name}: {stderr}");
626628
if !stdout.contains(&t.want_out) {
627-
assert_eq!(stdout, t.want_out, "test {}: stdout mismatch", t.name);
629+
assert_eq!(stdout, t.want_out, "test {test_name}: stdout mismatch");
628630
}
629631
}
630632
Err(err) => {
631633
let stdout = std::fs::read_to_string(stdout_path).unwrap();
632634
let stderr = std::fs::read_to_string(stderr_path).unwrap();
633-
assert_eq!(stdout, t.want_out, "test {}", t.name);
635+
assert_eq!(stdout, t.want_out, "test {test_name}");
634636
if !err.to_string().contains(&t.want_err) {
635-
assert_eq!(err.to_string(), t.want_err, "test {}: err mismatch", t.name);
637+
assert_eq!(err.to_string(), t.want_err, "test {test_name}: err mismatch");
636638
}
637-
assert!(stderr.is_empty(), "test {}: {}", t.name, stderr);
639+
assert!(stderr.is_empty(), "test {test_name}: {stderr}");
638640
}
639641
}
640642
}

src/cmd_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl crate::cmd::Command for CmdConfigGet {
5656
match ctx.config.get(&self.host, &self.key) {
5757
Ok(value) => writeln!(ctx.io.out, "{value}")?,
5858
Err(err) => {
59-
bail!("{}", err);
59+
bail!("{err}");
6060
}
6161
}
6262

@@ -89,7 +89,7 @@ impl crate::cmd::Command for CmdConfigSet {
8989

9090
// Set the value. If self.host is empty it will be top-level set.
9191
if let Err(err) = ctx.config.set(&self.host, &self.key, Some(&self.value)) {
92-
bail!("{}", err);
92+
bail!("{err}");
9393
}
9494

9595
// Unset the option in all other hosts if it's a mutually exclusive option.
@@ -111,7 +111,7 @@ impl crate::cmd::Command for CmdConfigSet {
111111
continue;
112112
}
113113
if let Err(err) = ctx.config.set(&host, &self.key, None) {
114-
bail!("{}", err);
114+
bail!("{err}");
115115
}
116116
}
117117
}
@@ -120,7 +120,7 @@ impl crate::cmd::Command for CmdConfigSet {
120120

121121
// Write the config file.
122122
if let Err(err) = ctx.config.write() {
123-
bail!("{}", err);
123+
bail!("{err}");
124124
}
125125

126126
Ok(())

src/cmd_file.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl crate::cmd::Command for CmdFileSnapshot {
295295
modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::ImportFiles(data),
296296
} = &resp
297297
else {
298-
anyhow::bail!("Unexpected response from engine import: {:?}", resp);
298+
anyhow::bail!("Unexpected response from engine import: {resp:?}");
299299
};
300300

301301
let object_id = data.object_id;
@@ -330,7 +330,7 @@ impl crate::cmd::Command for CmdFileSnapshot {
330330
// Save the snapshot locally.
331331
std::fs::write(&self.output_file, &data.contents.0)?;
332332
} else {
333-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
333+
anyhow::bail!("Unexpected response from engine: {resp:?}");
334334
}
335335

336336
writeln!(
@@ -705,8 +705,7 @@ fn get_import_format_from_extension(ext: &str) -> Result<kittycad::types::FileIm
705705
Ok(kittycad::types::FileImportFormat::Gltf)
706706
} else {
707707
anyhow::bail!(
708-
"unknown source format for file extension: {}. Try setting the `--src-format` flag explicitly or use a valid format.",
709-
ext
708+
"unknown source format for file extension: {ext}. Try setting the `--src-format` flag explicitly or use a valid format."
710709
)
711710
}
712711
}

src/cmd_kcl.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl crate::cmd::Command for CmdKclSnapshot {
352352
{
353353
(data.contents.0.clone(), session_data)
354354
} else {
355-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
355+
anyhow::bail!("Unexpected response from engine: {resp:?}");
356356
}
357357
}
358358
};
@@ -428,7 +428,7 @@ impl crate::cmd::Command for CmdKclView {
428428
// Save the snapshot locally.
429429
std::fs::write(&tmp_file, &data.contents.0)?;
430430
} else {
431-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
431+
anyhow::bail!("Unexpected response from engine: {resp:?}");
432432
}
433433

434434
let (width, height) = (ctx.io.tty_size)()?;
@@ -462,8 +462,7 @@ pub fn get_image_format_from_extension(ext: &str) -> Result<kittycad_modeling_cm
462462
Ok(format) => Ok(format),
463463
Err(_) => {
464464
anyhow::bail!(
465-
"unknown source format for file extension: {}. Try setting the `--src-format` flag explicitly or use a valid format.",
466-
ext
465+
"unknown source format for file extension: {ext}. Try setting the `--src-format` flag explicitly or use a valid format."
467466
)
468467
}
469468
}
@@ -597,7 +596,7 @@ impl crate::cmd::Command for CmdKclVolume {
597596
let format = ctx.format(&self.format)?;
598597
ctx.io.write_output(&format, &data)?;
599598
} else {
600-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
599+
anyhow::bail!("Unexpected response from engine: {resp:?}");
601600
}
602601

603602
if self.show_trace {
@@ -684,7 +683,7 @@ impl crate::cmd::Command for CmdKclMass {
684683
let format = ctx.format(&self.format)?;
685684
ctx.io.write_output(&format, &data)?;
686685
} else {
687-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
686+
anyhow::bail!("Unexpected response from engine: {resp:?}");
688687
}
689688

690689
if self.show_trace {
@@ -757,7 +756,7 @@ impl crate::cmd::Command for CmdKclCenterOfMass {
757756
let format = ctx.format(&self.format)?;
758757
ctx.io.write_output(&format, &data)?;
759758
} else {
760-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
759+
anyhow::bail!("Unexpected response from engine: {resp:?}");
761760
}
762761

763762
if self.show_trace {
@@ -844,7 +843,7 @@ impl crate::cmd::Command for CmdKclDensity {
844843
let format = ctx.format(&self.format)?;
845844
ctx.io.write_output(&format, &data)?;
846845
} else {
847-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
846+
anyhow::bail!("Unexpected response from engine: {resp:?}");
848847
}
849848

850849
if self.show_trace {
@@ -917,7 +916,7 @@ impl crate::cmd::Command for CmdKclSurfaceArea {
917916
let format = ctx.format(&self.format)?;
918917
ctx.io.write_output(&format, &data)?;
919918
} else {
920-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
919+
anyhow::bail!("Unexpected response from engine: {resp:?}");
921920
}
922921

923922
if self.show_trace {
@@ -1053,15 +1052,19 @@ fn get_modeling_settings_from_project_toml(input: &std::path::Path) -> Result<kc
10531052
let input = std::path::Path::new(input);
10541053
// Ensure the path exists.
10551054
if !input.exists() {
1056-
anyhow::bail!("file `{}` does not exist", input.display());
1055+
let input_display = input.display().to_string();
1056+
anyhow::bail!("file `{input_display}` does not exist");
10571057
}
10581058
// Get the directory if we don't already have one.
10591059
let dir = if input.is_dir() {
10601060
input.to_path_buf()
10611061
} else {
10621062
input
10631063
.parent()
1064-
.ok_or_else(|| anyhow::anyhow!("could not get parent directory of `{}`", input.display()))?
1064+
.ok_or_else(|| {
1065+
let input_display = input.display().to_string();
1066+
anyhow::anyhow!("could not get parent directory of `{input_display}`")
1067+
})?
10651068
.to_path_buf()
10661069
};
10671070

src/cmd_ml/cmd_text_to_cad.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ async fn get_image_bytes(
374374
modeling_response: OkModelingCmdResponse::ImportFiles(data),
375375
} = &resp
376376
else {
377-
anyhow::bail!("Unexpected response from engine import: {:?}", resp);
377+
anyhow::bail!("Unexpected response from engine import: {resp:?}");
378378
};
379379

380380
let object_id = data.object_id;
@@ -405,6 +405,6 @@ async fn get_image_bytes(
405405
// Save the snapshot locally.
406406
Ok(data.contents.0.clone())
407407
} else {
408-
anyhow::bail!("Unexpected response from engine: {:?}", resp);
408+
anyhow::bail!("Unexpected response from engine: {resp:?}");
409409
}
410410
}

0 commit comments

Comments
 (0)