Skip to content

Commit

Permalink
fix: fill the usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Dec 17, 2024
1 parent e74968c commit ef0c0ed
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 10 deletions.
5 changes: 4 additions & 1 deletion docs/mdbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- [`refetch_frequency`](./configuration/refetch_frequency.md)
- [`configs`](./configuration/configs.md)
- [Git hook](./configuration/Hook.md)
- [`files` (global)](./configuration/files-global.md)
- [`files`](./configuration/files-global.md)
- [`parallel`](./configuration/parallel.md)
- [`piped`](./configuration/piped.md)
- [`follow`](./configuration/follow.md)
Expand Down Expand Up @@ -70,3 +70,6 @@
- [`use_stdin`](./configuration/use_stdin.md)
- [`priority`](./configuration/priority.md)
- [Usage](./usage.md)
- [Commands](./usage/commands.md)
- [ENV variables](./usage/env.md)
- [Tips](./usage/tips.md)
38 changes: 38 additions & 0 deletions docs/mdbook/configuration/Hook.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
## Git hook

Contains settings for the git hook (commands, scripts, skip rules, etc.). You can specify any Git hook or your own custom, e.g. `test`

### Hook options

- [`files`](./files-global.md)
- [`parallel`](./parallel.md)
- [`piped`](./piped.md)
- [`follow`](./follow.md)
- [`exclude_tags`](./exclude_tags.md)
- [`skip`](./skip.md)
- [`only`](./only.md)
- [`commands`](./Commands.md)
- [`run`](./run.md)
- [`skip`](./skip.md)
- [`only`](./only.md)
- [`tags`](./tags.md)
- [`glob`](./glob.md)
- [`files`](./files.md)
- [`file_types`](./file_types.md)
- [`env`](./env.md)
- [`root`](./root.md)
- [`exclude`](./exclude.md)
- [`fail_text`](./fail_text.md)
- [`stage_fixed`](./stage_fixed.md)
- [`interactive`](./interactive.md)
- [`use_stdin`](./use_stdin.md)
- [`priority`](./priority.md)
- [`scripts`](./Scripts.md)
- [`runner`](./runner.md)
- [`skip`](./skip.md)
- [`only`](./only.md)
- [`tags`](./tags.md)
- [`env`](./env.md)
- [`fail_text`](./fail_text.md)
- [`stage_fixed`](./stage_fixed.md)
- [`interactive`](./interactive.md)
- [`use_stdin`](./use_stdin.md)
- [`priority`](./priority.md)
3 changes: 2 additions & 1 deletion docs/mdbook/configuration/file_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Filter files in a [`run`](./run.md) templates by their type. Supported types:
|`symlink` | A symlink file. |
|`not symlink` | Any non-symlink file. |

> [!IMPORTANT]
> IMPORTANT
>
> When passed multiple file types all constraints will be applied to the resulting list of files.
**Examples**
Expand Down
3 changes: 0 additions & 3 deletions docs/mdbook/configuration/remotes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
## `remotes`

> [!IMPORTANT]
> :test_tube: This feature is in **Beta** version
You can provide multiple remote configs if you want to share yours lefthook configurations across many projects. Lefthook will automatically download and merge configurations into your local `lefthook.yml`.

You can use [`extends`](./extends.md) but the paths must be relative to the remote repository root.
Expand Down
6 changes: 2 additions & 4 deletions docs/mdbook/configuration/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a mandatory option for a command. This is actually a command that is exe

You can use files templates that will be substituted with the appropriate files on execution:

- `{files}` - custom [`files`](#files) command result.
- `{files}` - custom [`files`](./files.md) command result.
- `{staged_files}` - staged files which you try to commit.
- `{push_files}` - files that are committed but not pushed.
- `{all_files}` - all files tracked by git.
Expand Down Expand Up @@ -72,7 +72,7 @@ pre-push:

Simply run `bundle exec rubocop` on all files with `.rb` extension excluding `application.rb` and `routes.rb` files.

> [!NOTE]
> NOTE
>
> `--force-exclusion` will apply `Exclude` configuration setting of Rubocop.

Expand Down Expand Up @@ -136,8 +136,6 @@ commit-msg:
run: 'test $(grep -c "^Signed-off-by: " {1}) -lt 2'
```

**Notes**

#### Rubocop

If using `{all_files}` with RuboCop, it will ignore RuboCop's `Exclude` configuration setting. To avoid this, pass `--force-exclusion`.
Expand Down
1 change: 0 additions & 1 deletion docs/mdbook/configuration/skip_output.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
### `skip_output`

> [!IMPORTANT]
> **DEPRECATED** This feature is deprecated and might be removed in future versions. Please, use `[output]` instead for managing verbosity.
You can manage the verbosity using the `skip_output` config. You can set whether lefthook should print some parts of its output.
Expand Down
27 changes: 27 additions & 0 deletions docs/mdbook/usage.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# Usage

- [Commands](./usage/commands.md)
- [`lefthook install`](./usage/commands.md#lefthook-install)
- [`lefthook uninstall`](./usage/commands.md#lefthook-uninstall)
- [`lefthook add`](./usage/commands.md#lefthook-add)
- [`lefthook run`](./usage/commands.md#lefthook-run)
- [`lefthook version`](./usage/commands.md#lefthook-version)
- [`lefthook self-update`](./usage/commands.md#lefthook-self-update)
- [ENV variables](./usage/env.md)
- [`LEFTHOOK`](./usage/env.md#lefthook)
- [`LEFTHOOK_EXCLUDE`](./usage/env.md#lefthook_exclude)
- [`LEFTHOOK_OUTPUT`](./usage/env.md#lefthook_output)
- [`LEFTHOOK_QUIET`](./usage/env.md#lefthook_quiet)
- [`LEFTHOOK_VERBOSE`](./usage/env.md#lefthook_verbose)
- [`LEFTHOOK_BIN`](./usage/env.md#lefthook_bin)
- [`NO_COLOR`](./usage/env.md#no_color)
- [`CLICOLOR_FORCE`](./usage/env.md#clicolor_force)
- [Tips](./usage/tips.md)
- [Local config](./usage/tips.md#local-config)
- [Disable lefthook in CI](./usage/tips.md#disable-lefthook-in-ci)
- [Commitlint example](./usage/tips.md#commitlint-example)
- [Parallel execution](./usage/tips.md#parallel-execution)
- [Concurrent files overrides](./usage/tips.md#concurrent-files-overrides)
- [Capture ARGS from git in the script](./usage/tips.md#capture-args-from-git-in-the-script)
- [Git LFS support](./usage/tips.md#git-lfs-support)
- [Pass stdin to a command or script](./usage/tips.md#pass-stdin-to-a-command-or-script)
- [Using an interactive command or script](./usage/tips.md#using-an-interactive-command-or-script)
121 changes: 121 additions & 0 deletions docs/mdbook/usage/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
## Commands

Use `lefthook help` or `lefthook <command> -h/--help` to discover available commands and their options.

### `lefthook install`

`lefthook install` creates an empty `lefthook.yml` if a configuration file does not exist and updates git hooks to use lefthook. Run `lefthook install` after cloning the git repo.

> NOTE
>
> NPM package `lefthook` installs the hooks in a postinstall script automatically.
### `lefthook uninstall`

`lefthook uninstall` clears git hooks affected by lefthook. If you have lefthook installed as an NPM package you should remove it manually.

### `lefthook add`

`lefthook add pre-commit` will create a file `.git/hooks/pre-commit`. This is the same lefthook does for [`install`](#lefthook-install) command but you don't need to create a configuration first.

To use custom scripts as hooks create the required directories with `lefthook add pre-commit --dirs`.

**Example**

```bash
$ lefthook add pre-push --dirs
```

Describe pre-push commands in `lefthook.yml`:

```yml
pre-push:
scripts:
"audit.sh":
runner: bash
```
Edit the script:
```bash
$ vim .lefthook/pre-push/audit.sh
...
```

Run `git push` and lefthook will run `bash audit.sh` as a pre-push hook.

### `lefthook run`

`lefthook run` executes the commands and scripts configured for a given hook. Generated hooks call `lefthook run` implicitly.

**Example**

```yml
# lefthook.yml

pre-commit:
commands:
lint:
run: yarn lint --fix

test:
commands:
js-test:
run: yarn test
```
Install the hook.
```bash
$ lefthook install
```

Run `test`.

```bash
$ lefthook run test # will run 'yarn test'
```

Commit changes.

```bash
$ git commit # will run pre-commit hook ('yarn lint --fix')
```

Or run manually also

```bash
$ lefthook run pre-commit
```

You can also specify a flag to run only some commands:

```bash
$ lefthook run pre-commit --commands lint
```

and optionally run either on all files (any `{staged_files}` placeholder acts as `{all_files}`) or a list of files:

```bash
$ lefthook run pre-commit --all-files
$ lefthook run pre-commit --file file1.js --file file2.js
```

(if both are specified, `--all-files` is ignored)

### `lefthook version`

`lefthook version` prints the current binary version. Print the commit hash with `lefthook version --full`

**Example**

```bash
$ lefthook version --full

1.1.3 bb099d13c24114d2859815d9d23671a32932ffe2
```

### `lefthook self-update`

`lefthook self-update` updates the binary with the latest lefthook release on Github. This command is available only if you install lefthook from sources or download the binary from the Github Releases. For other ways use package-specific commands to update lefthook.

70 changes: 70 additions & 0 deletions docs/mdbook/usage/env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## ENV variables

### `LEFTHOOK`

Use `LEFTHOOK=0 git ...` or `LEFTHOOK=false git ...` to disable lefthook when running git commands.

**Example**

```bash
LEFTHOOK=0 git commit -am "Lefthook skipped"
```

### `LEFTHOOK_EXCLUDE`

Use `LEFTHOOK_EXCLUDE={list of tags or command names to be excluded}` to skip some commands or scripts by tag or name (for commands only). See the [`exclude_tags`](../configuration/exclude_tags.md) configuration option for more details.

**Example**

```bash
LEFTHOOK_EXCLUDE=ruby,security,lint git commit -am "Skip some tag checks"
```

### `LEFTHOOK_OUTPUT`

Use `LEFTHOOK_OUTPUT={list of output values}` to specify what to print in your output. You can also set `LEFTHOOK_OUTPUT=false` to disable all output except for errors. Refer to the [`output`](../configuration/output.md) configuration option for more details.

**Example**

```bash
$ LEFTHOOK_OUTPUT=summary lefthook run pre-commit
summary: (done in 0.52 seconds)
✔️ lint
```

### `LEFTHOOK_QUIET`

You can skip some outputs printed by lefthook by setting the `LEFTHOOK_QUIET` environment variable. Provide a list of output types to be skipped. See the [`skip_output`](../configuration/skip_output.md) configuration option for more details.

**Example**

```bash
$ LEFTHOOK_QUIET=meta,execution lefthook run pre-commit

EXECUTE > lint

SUMMARY: (done in 0.01 seconds)
🥊 lint
```

### `LEFTHOOK_VERBOSE`

Set `LEFTHOOK_VERBOSE=1` or `LEFTHOOK_VERBOSE=true` to enable verbose printing.

### `LEFTHOOK_BIN`

Set `LEFTHOOK_BIN` to a location where lefthook is installed to use that instead of trying to detect from the it the PATH or from a package manager.

Useful for cases when:

- lefthook is installed multiple ways, and you want to be explicit about which one is used (example: installed through homebrew, but also is in Gemfile but you are using a ruby version manager like rbenv that prepends it to the path)
- debugging and/or developing lefthook

### `NO_COLOR`

Set `NO_COLOR=true` to disable colored output in lefthook and all subcommands that lefthook calls.

### `CLICOLOR_FORCE`

Set `CLICOLOR_FORCE=true` to force colored output in lefthook and all subcommands.

Loading

0 comments on commit ef0c0ed

Please sign in to comment.