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

Update rustfmt command line interface #4006

Merged
merged 15 commits into from
Jan 12, 2020

Conversation

topecongiro
Copy link
Contributor

This PR updates the rustfmt command-line interface in the following ways. Sorry in advance about the number of changes!

  • Remove --skip-children.
  • Remove --help=[command] and introduce the following alternatives:
    • --help=config can now be invoked via --config help
    • --help=file-lines is now shown with --help by default
  • Change the behavior of --print-config
    • Remove the output file argument: now always print to stdout
    • --print-config minimal prints the set of current configuration that differs from the default, without formatting files.
    • --print-config default prints the set of all configuration options with the default value
    • --print-config current prints the set of the current configuration, without formatting files
  • Remove --unstable-features.
  • Remove --color.
  • --help now prints longer help messages
    • This change is a side-effect of replacing getopts with structopt. Please see the following comment on how it changed.
  • Change the behavior of Config::used_options.
    • Return a set of configuration options that were explicitly set to values that are different from the default value

@topecongiro
Copy link
Contributor Author

rustfmt -h:

rustfmt 2.0.0-rc.1-nightly (265697c2 2020-01-08)
Format Rust code

USAGE:
    rustfmt [FLAGS] [OPTIONS] [--] [files]...

FLAGS:
    -c, --check                   Run in 'check' mode
        --error_on_unformatted    Error if unable to get comments or string literals within max_width, or they are left
                                  with trailing whitespaces (unstable)
    -l, --files-with-diff         Prints the names of files with diff
    -h, --help                    Prints help information
    -q, --quiet                   Print no output
    -r, --recursive               Recursively format submodules
    -V, --version                 Prints version information
    -v, --verbose                 Print verbose output

OPTIONS:
        --edition <2015|2018>                       Rust compiler edition
        --config-path <config-path>                 A path to the configuration file
        --print-config <default|current|minimal>    Print configuration options
        --emit <emit>                               Specify the format of rustfmt's output
        --file-lines <file-lines>                   Limit formatting to specified ranges [default: null]
        --config <inline-config>...                 Set options from command line

ARGS:
    <files>...    

rustfmt --help:

rustfmt 2.0.0-rc.1-nightly (265697c2 2020-01-08)
Format Rust code

USAGE:
    rustfmt [FLAGS] [OPTIONS] [--] [files]...

FLAGS:
    -c, --check                   
            Run in 'check' mode.
            
            Exits with 0 if input is formatted correctly. Exits with 1 and prints a diff if formatting is required.
        --error_on_unformatted    
            Error if unable to get comments or string literals within max_width, or they are left with trailing
            whitespaces (unstable)
    -l, --files-with-diff         
            Prints the names of files with diff

    -h, --help                    
            Prints help information

    -q, --quiet                   
            Print no output

    -r, --recursive               
            Recursively format submodules.
            
            Format all encountered modules recursively regardless of whether the modules are defined inline or in
            another file.
    -V, --version                 
            Prints version information

    -v, --verbose                 
            Print verbose output


OPTIONS:
        --edition <2015|2018>                       
            Rust compiler edition
            
            Specify which edition of the compiler to use when formatting code.
        --config-path <config-path>                 
            A path to the configuration file

        --print-config <default|current|minimal>    
            Print configuration options.
            
            `default` will print the default configuration options. `current` will print the current configuration
            options. `minimal` will print the minimal subset of the current configuration options.
        --emit <emit>                               
            Specify the format of rustfmt's output

        --file-lines <file-lines>                   
            Limit formatting to specified ranges.
            
            If you want to restrict reformatting to specific sets of lines, you can use the `--file-lines` option. Its
            argument is a JSON array of objects with `file` and `range` properties, where `file` is a file name, and
            `range` is an array representing a range of lines like `[7,13]`. Ranges are 1-based and inclusive of both
            end points. Specifying an empty array will result in no files being formatted. For example,
            
            ``` rustfmt --file-lines '[ {{\"file\":\"src/lib.rs\",\"range\":[7,13]}},
            {{\"file\":\"src/lib.rs\",\"range\":[21,29]}}, {{\"file\":\"src/foo.rs\",\"range\":[10,11]}},
            {{\"file\":\"src/foo.rs\",\"range\":[15,15]}}]' ```
            
            would format lines `7-13` and `21-29` of `src/lib.rs`, and lines `10-11`, and `15` of `src/foo.rs`. No other
            files would be formatted, even if they are included as out of line modules from `src/lib.rs`. [default:
            null]
        --config <inline-config>...                 
            Set options from command line.
            
            Set configuration options via command line by specifying a list of key-value pairs separated by commas
            (e.g., rustfmt --config=max_width=100,merge_imports=true). These settings precedes any other settings
            specified in configuration files.

ARGS:
    <files>...    
            

@topecongiro topecongiro merged commit cc56957 into rust-lang:master Jan 12, 2020
@topecongiro topecongiro deleted the rustfmt-cli branch January 12, 2020 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants