Skip to content

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

Merged
merged 3 commits into from
Jul 14, 2019

Conversation

calebcartwright
Copy link
Member

Closes #2817

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");
Copy link
Member Author

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.

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()?;
Copy link
Member Author

@calebcartwright calebcartwright Jul 13, 2019

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

Copy link
Contributor

@scampi scampi left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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();
Copy link
Contributor

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 {

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

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()?;
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@scampi scampi merged commit 0e6896b into rust-lang:master Jul 14, 2019
@topecongiro topecongiro added this to the 1.3.3 milestone Jul 15, 2019
@calebcartwright calebcartwright deleted the accept-manifest-path branch August 14, 2019 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo fmt doesn't accept --manifest-path
3 participants