Skip to content
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 --offline mode fallback to cargo fmt #3813

Merged
merged 3 commits into from
Oct 2, 2019

Conversation

calebcartwright
Copy link
Member

Closes #3811

@calebcartwright
Copy link
Member Author

calebcartwright commented Sep 27, 2019

Not entirely sure how to test, as I can't readily simulate networking issues in my env (disabling the internet connection doesn't make a difference) but the --offline flag is definitely available now

@calebcartwright calebcartwright changed the title feat: add --offline flag to cargo fmt add --offline flag to cargo fmt Sep 27, 2019
@@ -112,6 +116,18 @@ fn execute() -> i32 {
}
}

let mut cargo_metadata_additional_opts: Vec<String> = Vec::new();
Copy link
Member Author

Choose a reason for hiding this comment

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

I elected to go this route to make it easier to add any additional options in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm!

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.

As for tests, there is tests/cargo-fmt but tests there got ignored in PR #3690.
However, a test could be added to it, even if it needs to be ignored at the moment I think until the problem above is resolved. At least a test would exists ;o)
Maybe cargo tests could be an inspiration ?

src/cargo-fmt/main.rs Outdated Show resolved Hide resolved
@@ -112,6 +116,18 @@ fn execute() -> i32 {
}
}

let mut cargo_metadata_additional_opts: Vec<String> = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm!

@calebcartwright
Copy link
Member Author

calebcartwright commented Sep 27, 2019

As for tests, there is tests/cargo-fmt but tests there got ignored in PR #3690.
However, a test could be added to it, even if it needs to be ignored at the moment I think until the problem above is resolved. At least a test would exists ;o)
Maybe cargo tests could be an inspiration ?

I was hoping to be able to reproduce the networking issues referenced in #3811 to validate that including --offline would help, but still not sure if/how that could readily be done 🤷‍♂

Will add some tests to this though, at least to validate the new cargo fmt option 👍

"--message-format",
"short",
"--",
"--edition",
"2018",
]);
assert_eq!(true, o.quiet);
assert_eq!(true, o.offline);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that unit test is good enough... @topecongiro ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It'd be cool if one day we could have tests that validate that the correct options were passed to the cargo_metadata lib based on command line items passed to cargo fmt, though that seems like it might be a bit tricky

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I was not aware of cargo --offline, it seems to be a good addition to cargo-fmt.

Instead of adding --offline command-line option, I prefer to use the offline mode of cargo metadata by default, and if we somehow fail, then fallback to the online mode. I think there is no real benefit of having an option to switch between offline or online mode, it feels like something that should be hidden to users.

@calebcartwright
Copy link
Member Author

Instead of adding --offline command-line option, I prefer to use the offline mode of cargo metadata by default, and if we somehow fail, then fallback to the online mode. I think there is no real benefit of having an option to switch between offline or online mode, it feels like something that should be hidden to users.

SGTM, will work on making that switch. I'm not very familiar with cargo's --offline mode either, nor what sort of potential issues may occur with --offline. I'm guessing there is a reason why cargo's default is online, though presumably those reasons may not be applicable for rustfmt.

Would it be better to first try online mode to cargo_metadata, and then if there's a failure re-try with offline? Or do you want to go with your original approach of offline first?

@topecongiro
Copy link
Contributor

@calebcartwright You may have already read it, but I found the blog post by nrc which explains the cargo --offline quite nicely: https://www.ncameron.org/blog/cargo-offline/.

Would it be better to first try online mode to cargo_metadata, and then if there's a failure re-try with offline? Or do you want to go with your original approach of offline first?

Good point, I agree that trying the online mode first is a safer approach. We could switch the default to the offline mode once we are aware of the side effect of doing so.

@calebcartwright
Copy link
Member Author

Good point, I agree that trying the online mode first is a safer approach. We could switch the default to the offline mode once we are aware of the side effect of doing so.

Done!

@calebcartwright calebcartwright changed the title add --offline flag to cargo fmt add --offline mode fallback to cargo fmt Sep 30, 2019
@topecongiro topecongiro merged commit f4bc494 into rust-lang:master Oct 2, 2019
@topecongiro
Copy link
Contributor

Thanks!

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.

Why fmt must use internet to fmt code?
3 participants