Skip to content

Commit

Permalink
Add new invoke config values that allow for multiple invoke options
Browse files Browse the repository at this point in the history
For example, `per-file-or-dir = n` will run the command once per file if the
number of matching files is `< n`, otherwise it will run it per directory.
  • Loading branch information
autarch committed Mar 24, 2024
1 parent 2804e1d commit a056ff9
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 107 deletions.
12 changes: 12 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## 0.7.0

- Added three new `invoke` options:

- `"per-file-or-dir" = n`
- `"per-file-or-once" = n`
- `"per-dir-or-once" = n`

These will run the command in different ways depending on how many files or directories match the
command's config. This lets you pick the fastest way to run commands that can operate in different
ways. For example, with a large repo, `golangci-lint` is much faster when run once per directory
with a few directories. But once the number of directories is large enough, it's faster to just
run it once on the whole repo.

- `precious` will now emit a warning if your config file uses any of the deprecated config keys,
`run_mode` and `chdir`. Support for these options will be removed entirely in a future release.

Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,25 @@ command.

The `invoke` key tells `precious` how the command should be invoked.

| Value | Description |
| ------------ | ---------------------------------------------------------------------- |
| `"per-file"` | Run this command once for each matching file. **This is the default.** |
| `"per-dir"` | Run this command once for each matching directory. |
| `"once"` | Run this command once. |
| Value | Description |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `"per-file"` | Run this command once for each matching file. **This is the default.** |
| `"per-dir"` | Run this command once for each matching directory. |
| `"once"` | Run this command once. |
| `{ "per-file-or-dir" = n }` | If the number of matching files is less than `n`, run this command once for eaching matching file. Otherwise run it once for each matching directory. |
| `{ "per-file-or-once" = n }` | If the number of matching files is less than `n`, run this command once for eaching matching file. Otherwise run it once. |
| `{ "per-dir-or-once" = n }` | If the number of matching directories is less than `n`, run this command once for eaching matching directories. Otherwise run it once. |

The last three options are useful for optimizing how quickly the command runs. In some cases, a
command can be run in multiple ways, and how quickly it completes depends on how many files or
directories need to be linted or tidied.

The `golangci-lint` tool is a good example. Invoking it multiple times for a few directories can be
much faster than running it against the entire repo. However, once there are enough directories to
check, invoking it once for the entire repo will be faster.

Note that the `path_args` setting needs to work with both possible cases for these options. For
`golangci-lint`, that means setting it to `dir` when using `per-dir-or-once`.

#### `working_dir`

Expand Down
Loading

0 comments on commit a056ff9

Please sign in to comment.