Rustfmt: set a configuration option from the command line

Created on 14 May 2019  路  9Comments  路  Source: rust-lang/rustfmt

It should be possible to set an option from the CLI, e.g.,

$ rustfmt --format_doc_comments=true
feature-request good first issue

All 9 comments

I was also just looking for this feature!

From @shepmaster on discord: for Linux users, you can do the following "hack":

rustfmt file.rs --config-path =(echo normalize_doc_attributes = true)

I'm unfamiliar with the syntax you show; I used Bash's process substitution:

cargo +nightly fmt -- --config-path <(echo "format_doc_comments=true")

sorry, habit: that syntax is on zsh http://zsh.sourceforge.net/Doc/Release/Expansion.html#Process-Substitution. Thanks @shepmaster for spotting this.

Hi @shepmaster @scampi I would like to contribute and tackle this issue. It's my first time contributing to the project, could you provide me with a little guidance on how to get started on this?

@dannomayer Thanks for giving this a try!
I would add the logic to src/bin/main.rs:

  • add a new CLI option called --config
  • this accepts a pair of values separated by =
  • the value set this way has precedence over what is set in a rustfmt.toml file
  • add few tests ;o)

The module config contains everything that pertains to the Config struct.
Don't hesitate to open a WIP PR to get early feedbacks.

@Bruflot Thanks for giving this a try, looks good to me. I left some comments to the single option commit. Just open a PR in draft mode if you want to get early feedbacks ;o)

Hi @scampi , could you please assign me to this issue? I'll give it a try in a day or so.

And a question:

  • multiple --config invocations. Do we allow them? If so, what if some values are passed multiple times, either within one --config invocation or not? I'd suggest "later overrides former" policy.

@CreepySkeleton Thank you for your interest in contributing to rustfmt! I will assign you to this issue.

multiple --config invocations. Do we allow them? If so, what if some values are passed multiple times, either within one --config invocation or not? I'd suggest "later overrides former" policy.

I think that we can allow multiple --config and I agree that the later should override the values when there are multiple key-value pairs with the same key.

Was this page helpful?
0 / 5 - 0 ratings