Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ impl Display for ToolRunCommand {
}
}

fn find_verbose_flag(args: &[std::ffi::OsString]) -> Option<&str> {
for arg in args {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I might write this using args.iter().find(...) instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to use find_map as suggested

if let Some(arg_str) = arg.to_str() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I might use let Some(...) = ... else { continue } just to reduce nesting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used ? operator instead of let...else (clippy also suggested this)

if arg_str == "--verbose" {
return Some("--verbose");
}
// Match -v, -vv, -vvv, etc. (but not other flags starting with -v like -version)
if arg_str.starts_with("-v") && arg_str.chars().skip(1).all(|c| c == 'v') {
return Some(arg_str);
}
}
}
None
}

/// Run a command.
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn run(
Expand Down Expand Up @@ -309,11 +324,24 @@ pub(crate) async fn run(
.map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
}

return diagnostics::OperationDiagnostic::native_tls(client_builder.is_native_tls())
.with_context("tool")
let diagnostic =
diagnostics::OperationDiagnostic::native_tls(client_builder.is_native_tls());
let diagnostic = if let Some(verbose_flag) = find_verbose_flag(args) {
diagnostic.with_hint(format!(
"You provided `{}` to `{}`. Did you mean to provide it to `{}`? e.g., `{}`",
verbose_flag.cyan(),
target.cyan(),
invocation_source.to_string().cyan(),
format!("{invocation_source} {verbose_flag} {target}").green()
))
} else {
diagnostic.with_context("tool")
};
return diagnostic
.report(err)
.map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
}

Err(ProjectError::Requirements(err)) => {
let err = miette::Report::msg(format!("{err}"))
.context("Failed to resolve `--with` requirement");
Expand Down
Loading