`update_config()` was parsing the `write-mode` option once for each file
argument. This commit parses them once up front into a `CliOptions`
struct, which is then applied to the config before calling `run()`.
This commit tidies up handling of `write_mode` by setting it in the
config at the start, and removing the `write_mode` parameter threaded
throughout the formatting process.
Adds a config-path option for rustfmt. If this argument is provided,
it recursively searches the config-path for a rustfmt.toml file.
If file is not found, reverts to searching the file input path for the
config file or uses default options.
Previously errors were being silently ignored. Eg, if `rustfmt` did not
have permission to read a `rustfmt.toml` file, the default configuration
was used without informing the user.
`lookup_project_file` could erroneously find a *directory* named
`rustmfmt.toml` if there was one in its lookup path, and so ignore any
configuration file it should have found further up. The error handling
resulted in this silently using the default configuration.
Also from @marcusklaas:
Refactor code output functions
Specifically, `write_all_files` no longer returns a HashMap. It would sometimes
contain items, and sometimes be empty. When "fixed" newlines are required, this
must now be done with a separate call. The tests use this strategy and should now pass!
Usage messages traditionally use this as it contains the path that the
user provided to run the executable (e.g. `rustfmt` instead of
`/usr/local/bin/rustfmt`).
Fix#580 by allowing rustfmt to accept a list of files. This also
enables usage of shell wildcard expansion, although notably this does
not work with cmd.exe on Windows. For example: 'rustfmt *.rs' will
format all rust files in the current working directory.
- Change usage text to show rustfmt will accept a list of files
- Change "Using rustfmt config file: {}" message to
"Using rustfmt config file {} for {}"
- Change Operation::Format(PathBuf, WriteMode) to
Operation::Format(Vec<PathBuf>, WriteMode)
- Loop through Vec<PathBuf>, load config and call 'run' for each path
The existing help output is very verbose, overflowing a 50+ line
terminal. This moves the configuration options to a separate help flag
to make a mistyped command less annoying!
Adds support for receiving input from stdin in case no file was
specified. This is useful for editor/IDE integrations and other tooling.
To achieve clean output a new write-mode option called plain was added,
this option is mandatory when using stdin.
This removes usage of:
* PathExt
* split_last
* split_last_mut
* catch_panic
The catch_panic one was a little tricky as the ident interner needed to be
cloned across threads (a little unsafely), but it should otherwise be good to
go.