-
Notifications
You must be signed in to change notification settings - Fork 925
Add --manifest-path support to cargo fmt #3683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --manifest-path support to cargo fmt #3683
Conversation
if opts.manifest_path.is_some() { | ||
let specified_manifest_path = opts.manifest_path.unwrap(); | ||
if !specified_manifest_path.ends_with("Cargo.toml") { | ||
print_usage_to_stderr("the manifest-path must be a path to a Cargo.toml file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same error message cargo test
displays when the value is not a path to a Cargo.toml file, so I thought it would be good to do the same here.
src/cargo-fmt/main.rs
Outdated
let workspace_root_path = PathBuf::from(&metadata.workspace_root).canonicalize()?; | ||
let in_workspace_root = workspace_root_path == current_dir; | ||
let (in_workspace_root, current_dir_manifest) = if manifest_path.is_some() { | ||
let target_manifest = manifest_path.unwrap().canonicalize()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If specified, manifest_path
will already have a Cargo.toml
suffix so manifest_path
can just be used directly instead. Without this change, there would be problems discovering the targets when --manifest-path
points to a cargo workspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/cargo-fmt/main.rs
Outdated
@@ -90,7 +94,27 @@ fn execute() -> i32 { | |||
|
|||
let strategy = CargoFmtStrategy::from_opts(&opts); | |||
|
|||
handle_command_status(format_crate(verbosity, &strategy, opts.rustfmt_options)) | |||
if opts.manifest_path.is_some() { | |||
let specified_manifest_path = opts.manifest_path.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you replace these two lines with if let Some() =
?
if let Some(specified_manifest_path) = opts.manifest_path {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/cargo-fmt/main.rs
Outdated
let workspace_root_path = PathBuf::from(&metadata.workspace_root).canonicalize()?; | ||
let in_workspace_root = workspace_root_path == current_dir; | ||
let (in_workspace_root, current_dir_manifest) = if manifest_path.is_some() { | ||
let target_manifest = manifest_path.unwrap().canonicalize()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update these two lines as the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Closes #2817