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 ability to read --{in,ex}clude value from stdin #790

Merged
merged 1 commit into from Nov 9, 2020

Commits on Sep 9, 2020

  1. Add ability to read --{in,ex}clude value from stdin

    Today, `dotnet-format` accepts space-separated list of files. This
    allows us to pass files via shell's native globbing expansion,
    heredoc style redirections as well as via pipelines (see dotnet#551 for
    examples). However, in case of pipeline it requires a second utility
    (`xarg`) to transform pipeline input as space-separated list to
    `dotnet-format`.
    
    This PR implements native pipeline reading support for `--include`
    and `--exclude` options, while keeping the space-separated list
    intact.
    
    #### Usage examples
    
    1. Include all C# source files under `tests/Utilities` directory
    that are in git source tree:
    
        ```sh
        git ls-files :/tests/Utilities/*.cs | dotnet format --include - --folder
        ```
    3. Format all C# source files in last commit:
    
        ```sh
        git show --name-only --pretty="" | dotnet format --include - --folder
        ```
    2. Exclude certain `*.cs` and `*.vb` files using `ls(1)`:
    
        ```sh
        ls ../../../../../src/generated/{*.cs,*.vb} | dotnet format --exclude /dev/stdin --folder
        ```
    
    #### Rules
    
    * Based on Guideline 13 of [IEEE
    1003.1-2017](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02)
    (POSIX),  it accepts `-` as an explicit marker for stdin with
    addition of:
      * `/dev/stdin` - which is a universal synonym of `-` on all Unices.
      * It *only* accepts explicit markers (`/dev/stdin` or `-`) and
      does not implicitly deduce the output if standard input was redirected,
      but marker was not present. This is because our usage is multi-purpose
      (both `--include` and `--exclude`).
    * It is an error if both `--include` and `--exclude` are using stdin
    marker (`/dev/stdin` or `-`).
    
    #### Limitations / future considerations
    
    * Currently, it reads the entire input from pipeline in `include`/`exclude`
    buffer, and then runs the operation on the whole batch. In order
    to make it true pipeline friendly, it would require some refactoring;
    so files are `yield return`'d and enumerator can dispatch format
    operation per file.
    * At present, we do not have out-of-process functional test mechanism
    for CLI to effectively validate these kind of use-cases (redirection
    and shell globbing vs. dotnet-format's built-in globbing support);
    so no tests are included in this PR.
    am11 committed Sep 9, 2020
    Copy the full SHA
    8db0847 View commit details
    Browse the repository at this point in the history