1
0
mirror of https://github.com/j178/prek.git synced 2026-04-25 02:11:36 +02:00

Move identify and init-template-dir under the prek util top-level command (#1574)

The old `prek init-template-dir` is hide but still works.
This commit is contained in:
Jo
2026-02-05 19:39:52 +08:00
committed by GitHub
parent decff291e6
commit 16f514bafd
7 changed files with 238 additions and 152 deletions
+30 -15
View File
@@ -202,9 +202,9 @@ pub(crate) struct GlobalArgs {
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
/// Install the prek git hook.
/// Install prek as a git hook under the `.git/hooks/` directory.
Install(InstallArgs),
/// Create hook environments for all hooks used in the config file.
/// Create environments for all hooks used in the config file.
///
/// This command does not install the git hook. To install the git hook along with the hook environments in one command, use `prek install --install-hooks`.
InstallHooks(InstallHooksArgs),
@@ -212,17 +212,15 @@ pub(crate) enum Command {
Run(Box<RunArgs>),
/// List available hooks.
List(ListArgs),
/// Show file identification tags.
Identify(IdentifyArgs),
/// Uninstall the prek git hook.
/// Uninstall prek from git hooks.
Uninstall(UninstallArgs),
/// Validate `.pre-commit-config.yaml` files.
/// Validate configuration files (prek.toml or .pre-commit-config.yaml).
ValidateConfig(ValidateConfigArgs),
/// Validate `.pre-commit-hooks.yaml` files.
ValidateManifest(ValidateManifestArgs),
/// Produce a sample `.pre-commit-config.yaml` file.
/// Produce a sample configuration file (prek.toml or .pre-commit-config.yaml).
SampleConfig(SampleConfigArgs),
/// Auto-update pre-commit config to the latest repos' versions.
/// Auto-update the `rev` field of repositories in the config file to the latest version.
#[command(alias = "autoupdate")]
AutoUpdate(AutoUpdateArgs),
/// Manage the prek cache.
@@ -234,19 +232,18 @@ pub(crate) enum Command {
#[command(hide = true)]
Clean,
/// Install hook script in a directory intended for use with `git config init.templateDir`.
#[command(alias = "init-templatedir")]
#[command(alias = "init-templatedir", hide = true)]
InitTemplateDir(InitTemplateDirArgs),
/// Try the pre-commit hooks in the current repo.
TryRepo(Box<TryRepoArgs>),
/// The implementation of the `pre-commit` hook.
/// The implementation of the prek hook script that is installed in the `.git/hooks/` directory.
#[command(hide = true)]
HookImpl(HookImplArgs),
/// Utility commands.
Util(UtilNamespace),
/// `prek` self management.
#[command(name = "self")]
Self_(SelfNamespace),
/// Generate shell completion scripts.
#[command(hide = true)]
GenerateShellCompletion(GenerateShellCompletionArgs),
}
#[derive(Debug, Args)]
@@ -287,7 +284,7 @@ pub(crate) struct InstallArgs {
#[arg(short = 'f', long)]
pub(crate) overwrite: bool,
/// Create hook environments for all hooks used in the config file.
/// Create environments for all hooks used in the config file.
#[arg(long)]
pub(crate) install_hooks: bool,
@@ -304,7 +301,7 @@ pub(crate) struct InstallArgs {
#[arg(short = 't', long = "hook-type", value_name = "HOOK_TYPE", value_enum)]
pub(crate) hook_types: Vec<HookType>,
/// Allow a missing `pre-commit` configuration file.
/// Allow a missing configuration file.
#[arg(long)]
pub(crate) allow_missing_config: bool,
}
@@ -713,6 +710,24 @@ pub(crate) struct CacheNamespace {
pub(crate) command: CacheCommand,
}
#[derive(Debug, Args)]
pub(crate) struct UtilNamespace {
#[command(subcommand)]
pub(crate) command: UtilCommand,
}
#[derive(Debug, Subcommand)]
pub(crate) enum UtilCommand {
/// Show file identification tags.
Identify(IdentifyArgs),
/// Install hook script in a directory intended for use with `git config init.templateDir`.
#[command(alias = "init-templatedir")]
InitTemplateDir(InitTemplateDirArgs),
/// Generate shell completion scripts.
#[command(hide = true)]
GenerateShellCompletion(GenerateShellCompletionArgs),
}
#[derive(Debug, Subcommand)]
pub(crate) enum CacheCommand {
/// Show the location of the prek cache.
+35 -18
View File
@@ -19,7 +19,9 @@ use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, Layer};
use crate::cleanup::cleanup;
use crate::cli::{CacheCommand, CacheNamespace, Cli, Command, ExitStatus};
use crate::cli::{
CacheCommand, CacheNamespace, Cli, Command, ExitStatus, UtilCommand, UtilNamespace,
};
#[cfg(feature = "self-update")]
use crate::cli::{SelfCommand, SelfNamespace, SelfUpdateArgs};
use crate::printer::Printer;
@@ -299,11 +301,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
)
.await
}
Command::Identify(args) => {
show_settings!(args);
cli::identify(&args.paths, args.output_format, printer)
}
Command::HookImpl(args) => {
show_settings!(args);
@@ -381,6 +378,38 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
)
.await
}
Command::Util(UtilNamespace { command }) => match command {
UtilCommand::Identify(args) => {
show_settings!(args);
cli::identify(&args.paths, args.output_format, printer)
}
UtilCommand::InitTemplateDir(args) => {
show_settings!(args);
cli::init_template_dir(
&store,
args.directory,
cli.globals.config,
args.hook_types,
args.no_allow_missing_config,
cli.globals.refresh,
printer,
)
.await
}
UtilCommand::GenerateShellCompletion(args) => {
show_settings!(args);
let mut command = Cli::command();
let bin_name = command
.get_bin_name()
.unwrap_or_else(|| command.get_name())
.to_owned();
clap_complete::generate(args.shell, &mut command, bin_name, &mut std::io::stdout());
Ok(ExitStatus::Success)
}
},
#[cfg(feature = "self-update")]
Command::Self_(SelfNamespace {
command:
@@ -409,18 +438,6 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
anyhow::bail!("{msg}");
}
Command::GenerateShellCompletion(args) => {
show_settings!(args);
let mut command = Cli::command();
let bin_name = command
.get_bin_name()
.unwrap_or_else(|| command.get_name())
.to_owned();
clap_complete::generate(args.shell, &mut command, bin_name, &mut std::io::stdout());
Ok(ExitStatus::Success)
}
Command::InitTemplateDir(args) => {
show_settings!(args);
+2
View File
@@ -18,6 +18,7 @@ fn identify_text_with_missing_paths() -> anyhow::Result<()> {
context.filters(),
context
.command()
.arg("util")
.arg("identify")
.arg(".")
.arg("hello.py")
@@ -50,6 +51,7 @@ fn identify_json_with_missing_paths() -> anyhow::Result<()> {
context.filters(),
context
.command()
.arg("util")
.arg("identify")
.arg("--output-format")
.arg("json")
+38
View File
@@ -459,6 +459,44 @@ fn init_template_dir() -> anyhow::Result<()> {
Ok(())
}
/// Tests `prek util init-template-dir` works.
#[test]
fn util_init_template_dir() {
let context = TestContext::new();
context.init_project();
cmd_snapshot!(context.filters(), context.command().arg("util").arg("init-templatedir").arg(".git"), @r#"
success: true
exit_code: 0
----- stdout -----
prek installed at `.git/hooks/pre-commit`
----- stderr -----
warning: git config `init.templateDir` not set to the target directory, try `git config --global init.templateDir '.git'`
"#);
insta::with_settings!(
{ filters => context.filters() },
{
assert_snapshot!(context.read(".git/hooks/pre-commit"), @r#"
#!/bin/sh
# File generated by prek: https://github.com/j178/prek
# ID: 182c10f181da4464a3eec51b83331688
HERE="$(cd "$(dirname "$0")" && pwd)"
PREK="[CURRENT_EXE]"
# Check if the full path to prek is executable, otherwise fallback to PATH
if [ ! -x "$PREK" ]; then
PREK="prek"
fi
exec "$PREK" hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit --skip-on-missing-config -- "$@"
"#);
}
);
}
/// Tests `prek init-template-dir` in a non-git repository.
#[test]
fn init_template_dir_non_git_repo() {
+8 -9
View File
@@ -2164,23 +2164,22 @@ fn selectors_completion() -> Result<()> {
// Unrelated non-project dir should not appear in subdir suggestions
cwd.child("scratch").create_dir_all()?;
cmd_snapshot!(context.filters(), context.run().env("COMPLETE", "fish").arg("--").arg("prek").arg(""), @r"
cmd_snapshot!(context.filters(), context.run().env("COMPLETE", "fish").arg("--").arg("prek").arg(""), @"
success: true
exit_code: 0
----- stdout -----
install Install the prek git hook
install-hooks Create hook environments for all hooks used in the config file
install Install prek as a git hook under the `.git/hooks/` directory
install-hooks Create environments for all hooks used in the config file
run Run hooks
list List available hooks
identify Show file identification tags
uninstall Uninstall the prek git hook
validate-config Validate `.pre-commit-config.yaml` files
uninstall Uninstall prek from git hooks
validate-config Validate configuration files (prek.toml or .pre-commit-config.yaml)
validate-manifest Validate `.pre-commit-hooks.yaml` files
sample-config Produce a sample `.pre-commit-config.yaml` file
auto-update Auto-update pre-commit config to the latest repos' versions
sample-config Produce a sample configuration file (prek.toml or .pre-commit-config.yaml)
auto-update Auto-update the `rev` field of repositories in the config file to the latest version
cache Manage the prek cache
init-template-dir Install hook script in a directory intended for use with `git config init.templateDir`
try-repo Try the pre-commit hooks in the current repo
util Utility commands
self `prek` self management
app/
app:
+124 -109
View File
@@ -12,25 +12,24 @@ prek [OPTIONS] [HOOK|PROJECT]... [COMMAND]
<h3 class="cli-reference">Commands</h3>
<dl class="cli-reference"><dt><a href="#prek-install"><code>prek install</code></a></dt><dd><p>Install the prek git hook</p></dd>
<dt><a href="#prek-install-hooks"><code>prek install-hooks</code></a></dt><dd><p>Create hook environments for all hooks used in the config file</p></dd>
<dl class="cli-reference"><dt><a href="#prek-install"><code>prek install</code></a></dt><dd><p>Install prek as a git hook under the <code>.git/hooks/</code> directory</p></dd>
<dt><a href="#prek-install-hooks"><code>prek install-hooks</code></a></dt><dd><p>Create environments for all hooks used in the config file</p></dd>
<dt><a href="#prek-run"><code>prek run</code></a></dt><dd><p>Run hooks</p></dd>
<dt><a href="#prek-list"><code>prek list</code></a></dt><dd><p>List available hooks</p></dd>
<dt><a href="#prek-identify"><code>prek identify</code></a></dt><dd><p>Show file identification tags</p></dd>
<dt><a href="#prek-uninstall"><code>prek uninstall</code></a></dt><dd><p>Uninstall the prek git hook</p></dd>
<dt><a href="#prek-validate-config"><code>prek validate-config</code></a></dt><dd><p>Validate <code>.pre-commit-config.yaml</code> files</p></dd>
<dt><a href="#prek-uninstall"><code>prek uninstall</code></a></dt><dd><p>Uninstall prek from git hooks</p></dd>
<dt><a href="#prek-validate-config"><code>prek validate-config</code></a></dt><dd><p>Validate configuration files (prek.toml or .pre-commit-config.yaml)</p></dd>
<dt><a href="#prek-validate-manifest"><code>prek validate-manifest</code></a></dt><dd><p>Validate <code>.pre-commit-hooks.yaml</code> files</p></dd>
<dt><a href="#prek-sample-config"><code>prek sample-config</code></a></dt><dd><p>Produce a sample <code>.pre-commit-config.yaml</code> file</p></dd>
<dt><a href="#prek-auto-update"><code>prek auto-update</code></a></dt><dd><p>Auto-update pre-commit config to the latest repos' versions</p></dd>
<dt><a href="#prek-sample-config"><code>prek sample-config</code></a></dt><dd><p>Produce a sample configuration file (prek.toml or .pre-commit-config.yaml)</p></dd>
<dt><a href="#prek-auto-update"><code>prek auto-update</code></a></dt><dd><p>Auto-update the <code>rev</code> field of repositories in the config file to the latest version</p></dd>
<dt><a href="#prek-cache"><code>prek cache</code></a></dt><dd><p>Manage the prek cache</p></dd>
<dt><a href="#prek-init-template-dir"><code>prek init-template-dir</code></a></dt><dd><p>Install hook script in a directory intended for use with <code>git config init.templateDir</code></p></dd>
<dt><a href="#prek-try-repo"><code>prek try-repo</code></a></dt><dd><p>Try the pre-commit hooks in the current repo</p></dd>
<dt><a href="#prek-util"><code>prek util</code></a></dt><dd><p>Utility commands</p></dd>
<dt><a href="#prek-self"><code>prek self</code></a></dt><dd><p><code>prek</code> self management</p></dd>
</dl>
## prek install
Install the prek git hook
Install prek as a git hook under the `.git/hooks/` directory
<h3 class="cli-reference">Usage</h3>
@@ -58,7 +57,7 @@ prek install [OPTIONS] [HOOK|PROJECT]...
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt id="prek-install--allow-missing-config"><a href="#prek-install--allow-missing-config"><code>--allow-missing-config</code></a></dt><dd><p>Allow a missing <code>pre-commit</code> configuration file</p>
<dl class="cli-reference"><dt id="prek-install--allow-missing-config"><a href="#prek-install--allow-missing-config"><code>--allow-missing-config</code></a></dt><dd><p>Allow a missing configuration file</p>
</dd><dt id="prek-install--cd"><a href="#prek-install--cd"><code>--cd</code></a>, <code>-C</code> <i>dir</i></dt><dd><p>Change to directory before running</p>
</dd><dt id="prek-install--color"><a href="#prek-install--color"><code>--color</code></a> <i>color</i></dt><dd><p>Whether to use color in output</p>
<p>May also be set with the <code>PREK_COLOR</code> environment variable.</p><p>[default: auto]</p><p>Possible values:</p>
@@ -84,7 +83,7 @@ prek install [OPTIONS] [HOOK|PROJECT]...
<li><code>pre-push</code></li>
<li><code>pre-rebase</code></li>
<li><code>prepare-commit-msg</code></li>
</ul></dd><dt id="prek-install--install-hooks"><a href="#prek-install--install-hooks"><code>--install-hooks</code></a></dt><dd><p>Create hook environments for all hooks used in the config file</p>
</ul></dd><dt id="prek-install--install-hooks"><a href="#prek-install--install-hooks"><code>--install-hooks</code></a></dt><dd><p>Create environments for all hooks used in the config file</p>
</dd><dt id="prek-install--log-file"><a href="#prek-install--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
</dd><dt id="prek-install--no-progress"><a href="#prek-install--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
<p>For example, spinners or progress bars.</p>
@@ -112,7 +111,7 @@ prek install [OPTIONS] [HOOK|PROJECT]...
## prek install-hooks
Create hook environments for all hooks used in the config file.
Create environments for all hooks used in the config file.
This command does not install the git hook. To install the git hook along with the hook environments in one command, use `prek install --install-hooks`.
@@ -370,50 +369,9 @@ prek list [OPTIONS] [HOOK|PROJECT]...
</dd><dt id="prek-list--version"><a href="#prek-list--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek identify
Show file identification tags
<h3 class="cli-reference">Usage</h3>
```
prek identify [OPTIONS] [PATH]...
```
<h3 class="cli-reference">Arguments</h3>
<dl class="cli-reference"><dt id="prek-identify--paths"><a href="#prek-identify--paths"><code>PATH</code></a></dt><dd><p>The path(s) to the file(s) to identify</p>
</dd></dl>
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt id="prek-identify--cd"><a href="#prek-identify--cd"><code>--cd</code></a>, <code>-C</code> <i>dir</i></dt><dd><p>Change to directory before running</p>
</dd><dt id="prek-identify--color"><a href="#prek-identify--color"><code>--color</code></a> <i>color</i></dt><dd><p>Whether to use color in output</p>
<p>May also be set with the <code>PREK_COLOR</code> environment variable.</p><p>[default: auto]</p><p>Possible values:</p>
<ul>
<li><code>auto</code>: Enables colored output only when the output is going to a terminal or TTY with support</li>
<li><code>always</code>: Enables colored output regardless of the detected environment</li>
<li><code>never</code>: Disables colored output</li>
</ul></dd><dt id="prek-identify--config"><a href="#prek-identify--config"><code>--config</code></a>, <code>-c</code> <i>config</i></dt><dd><p>Path to alternate config file</p>
</dd><dt id="prek-identify--help"><a href="#prek-identify--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
</dd><dt id="prek-identify--log-file"><a href="#prek-identify--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
</dd><dt id="prek-identify--no-progress"><a href="#prek-identify--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
<p>For example, spinners or progress bars.</p>
</dd><dt id="prek-identify--output-format"><a href="#prek-identify--output-format"><code>--output-format</code></a> <i>output-format</i></dt><dd><p>The output format</p>
<p>[default: text]</p><p>Possible values:</p>
<ul>
<li><code>text</code></li>
<li><code>json</code></li>
</ul></dd><dt id="prek-identify--quiet"><a href="#prek-identify--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-identify--refresh"><a href="#prek-identify--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
</dd><dt id="prek-identify--verbose"><a href="#prek-identify--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output</p>
</dd><dt id="prek-identify--version"><a href="#prek-identify--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek uninstall
Uninstall the prek git hook
Uninstall prek from git hooks
<h3 class="cli-reference">Usage</h3>
@@ -459,7 +417,7 @@ prek uninstall [OPTIONS]
## prek validate-config
Validate `.pre-commit-config.yaml` files
Validate configuration files (prek.toml or .pre-commit-config.yaml)
<h3 class="cli-reference">Usage</h3>
@@ -531,7 +489,7 @@ prek validate-manifest [OPTIONS] [MANIFEST]...
## prek sample-config
Produce a sample `.pre-commit-config.yaml` file
Produce a sample configuration file (prek.toml or .pre-commit-config.yaml)
<h3 class="cli-reference">Usage</h3>
@@ -569,7 +527,7 @@ prek sample-config [OPTIONS]
## prek auto-update
Auto-update pre-commit config to the latest repos' versions
Auto-update the `rev` field of repositories in the config file to the latest version
<h3 class="cli-reference">Usage</h3>
@@ -749,58 +707,6 @@ prek cache size [OPTIONS]
</dd><dt id="prek-cache-size--version"><a href="#prek-cache-size--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek init-template-dir
Install hook script in a directory intended for use with `git config init.templateDir`
<h3 class="cli-reference">Usage</h3>
```
prek init-template-dir [OPTIONS] <DIRECTORY>
```
<h3 class="cli-reference">Arguments</h3>
<dl class="cli-reference"><dt id="prek-init-template-dir--directory"><a href="#prek-init-template-dir--directory"><code>DIRECTORY</code></a></dt><dd><p>The directory in which to write the hook script</p>
</dd></dl>
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt id="prek-init-template-dir--cd"><a href="#prek-init-template-dir--cd"><code>--cd</code></a>, <code>-C</code> <i>dir</i></dt><dd><p>Change to directory before running</p>
</dd><dt id="prek-init-template-dir--color"><a href="#prek-init-template-dir--color"><code>--color</code></a> <i>color</i></dt><dd><p>Whether to use color in output</p>
<p>May also be set with the <code>PREK_COLOR</code> environment variable.</p><p>[default: auto]</p><p>Possible values:</p>
<ul>
<li><code>auto</code>: Enables colored output only when the output is going to a terminal or TTY with support</li>
<li><code>always</code>: Enables colored output regardless of the detected environment</li>
<li><code>never</code>: Disables colored output</li>
</ul></dd><dt id="prek-init-template-dir--config"><a href="#prek-init-template-dir--config"><code>--config</code></a>, <code>-c</code> <i>config</i></dt><dd><p>Path to alternate config file</p>
</dd><dt id="prek-init-template-dir--help"><a href="#prek-init-template-dir--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
</dd><dt id="prek-init-template-dir--hook-type"><a href="#prek-init-template-dir--hook-type"><code>--hook-type</code></a>, <code>-t</code> <i>hook-type</i></dt><dd><p>Which hook type(s) to install.</p>
<p>Specifies which git hook stage(s) you want to install the hook script for. Can be specified multiple times to install hooks for multiple stages.</p>
<p>If not specified, uses <code>default_install_hook_types</code> from the config file, or defaults to <code>pre-commit</code> if that is also not set.</p>
<p>Possible values:</p>
<ul>
<li><code>commit-msg</code></li>
<li><code>post-checkout</code></li>
<li><code>post-commit</code></li>
<li><code>post-merge</code></li>
<li><code>post-rewrite</code></li>
<li><code>pre-commit</code></li>
<li><code>pre-merge-commit</code></li>
<li><code>pre-push</code></li>
<li><code>pre-rebase</code></li>
<li><code>prepare-commit-msg</code></li>
</ul></dd><dt id="prek-init-template-dir--log-file"><a href="#prek-init-template-dir--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
</dd><dt id="prek-init-template-dir--no-allow-missing-config"><a href="#prek-init-template-dir--no-allow-missing-config"><code>--no-allow-missing-config</code></a></dt><dd><p>Assume cloned repos should have a <code>pre-commit</code> config</p>
</dd><dt id="prek-init-template-dir--no-progress"><a href="#prek-init-template-dir--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
<p>For example, spinners or progress bars.</p>
</dd><dt id="prek-init-template-dir--quiet"><a href="#prek-init-template-dir--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-init-template-dir--refresh"><a href="#prek-init-template-dir--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
</dd><dt id="prek-init-template-dir--verbose"><a href="#prek-init-template-dir--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output</p>
</dd><dt id="prek-init-template-dir--version"><a href="#prek-init-template-dir--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek try-repo
Try the pre-commit hooks in the current repo
@@ -891,6 +797,115 @@ prek try-repo [OPTIONS] <REPO> [HOOK|PROJECT]...
</dd><dt id="prek-try-repo--version"><a href="#prek-try-repo--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek util
Utility commands
<h3 class="cli-reference">Usage</h3>
```
prek util [OPTIONS] <COMMAND>
```
<h3 class="cli-reference">Commands</h3>
<dl class="cli-reference"><dt><a href="#prek-util-identify"><code>prek util identify</code></a></dt><dd><p>Show file identification tags</p></dd>
<dt><a href="#prek-util-init-template-dir"><code>prek util init-template-dir</code></a></dt><dd><p>Install hook script in a directory intended for use with <code>git config init.templateDir</code></p></dd>
</dl>
### prek util identify
Show file identification tags
<h3 class="cli-reference">Usage</h3>
```
prek util identify [OPTIONS] [PATH]...
```
<h3 class="cli-reference">Arguments</h3>
<dl class="cli-reference"><dt id="prek-util-identify--paths"><a href="#prek-util-identify--paths"><code>PATH</code></a></dt><dd><p>The path(s) to the file(s) to identify</p>
</dd></dl>
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt id="prek-util-identify--cd"><a href="#prek-util-identify--cd"><code>--cd</code></a>, <code>-C</code> <i>dir</i></dt><dd><p>Change to directory before running</p>
</dd><dt id="prek-util-identify--color"><a href="#prek-util-identify--color"><code>--color</code></a> <i>color</i></dt><dd><p>Whether to use color in output</p>
<p>May also be set with the <code>PREK_COLOR</code> environment variable.</p><p>[default: auto]</p><p>Possible values:</p>
<ul>
<li><code>auto</code>: Enables colored output only when the output is going to a terminal or TTY with support</li>
<li><code>always</code>: Enables colored output regardless of the detected environment</li>
<li><code>never</code>: Disables colored output</li>
</ul></dd><dt id="prek-util-identify--config"><a href="#prek-util-identify--config"><code>--config</code></a>, <code>-c</code> <i>config</i></dt><dd><p>Path to alternate config file</p>
</dd><dt id="prek-util-identify--help"><a href="#prek-util-identify--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
</dd><dt id="prek-util-identify--log-file"><a href="#prek-util-identify--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
</dd><dt id="prek-util-identify--no-progress"><a href="#prek-util-identify--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
<p>For example, spinners or progress bars.</p>
</dd><dt id="prek-util-identify--output-format"><a href="#prek-util-identify--output-format"><code>--output-format</code></a> <i>output-format</i></dt><dd><p>The output format</p>
<p>[default: text]</p><p>Possible values:</p>
<ul>
<li><code>text</code></li>
<li><code>json</code></li>
</ul></dd><dt id="prek-util-identify--quiet"><a href="#prek-util-identify--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-util-identify--refresh"><a href="#prek-util-identify--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
</dd><dt id="prek-util-identify--verbose"><a href="#prek-util-identify--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output</p>
</dd><dt id="prek-util-identify--version"><a href="#prek-util-identify--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
### prek util init-template-dir
Install hook script in a directory intended for use with `git config init.templateDir`
<h3 class="cli-reference">Usage</h3>
```
prek util init-template-dir [OPTIONS] <DIRECTORY>
```
<h3 class="cli-reference">Arguments</h3>
<dl class="cli-reference"><dt id="prek-util-init-template-dir--directory"><a href="#prek-util-init-template-dir--directory"><code>DIRECTORY</code></a></dt><dd><p>The directory in which to write the hook script</p>
</dd></dl>
<h3 class="cli-reference">Options</h3>
<dl class="cli-reference"><dt id="prek-util-init-template-dir--cd"><a href="#prek-util-init-template-dir--cd"><code>--cd</code></a>, <code>-C</code> <i>dir</i></dt><dd><p>Change to directory before running</p>
</dd><dt id="prek-util-init-template-dir--color"><a href="#prek-util-init-template-dir--color"><code>--color</code></a> <i>color</i></dt><dd><p>Whether to use color in output</p>
<p>May also be set with the <code>PREK_COLOR</code> environment variable.</p><p>[default: auto]</p><p>Possible values:</p>
<ul>
<li><code>auto</code>: Enables colored output only when the output is going to a terminal or TTY with support</li>
<li><code>always</code>: Enables colored output regardless of the detected environment</li>
<li><code>never</code>: Disables colored output</li>
</ul></dd><dt id="prek-util-init-template-dir--config"><a href="#prek-util-init-template-dir--config"><code>--config</code></a>, <code>-c</code> <i>config</i></dt><dd><p>Path to alternate config file</p>
</dd><dt id="prek-util-init-template-dir--help"><a href="#prek-util-init-template-dir--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
</dd><dt id="prek-util-init-template-dir--hook-type"><a href="#prek-util-init-template-dir--hook-type"><code>--hook-type</code></a>, <code>-t</code> <i>hook-type</i></dt><dd><p>Which hook type(s) to install.</p>
<p>Specifies which git hook stage(s) you want to install the hook script for. Can be specified multiple times to install hooks for multiple stages.</p>
<p>If not specified, uses <code>default_install_hook_types</code> from the config file, or defaults to <code>pre-commit</code> if that is also not set.</p>
<p>Possible values:</p>
<ul>
<li><code>commit-msg</code></li>
<li><code>post-checkout</code></li>
<li><code>post-commit</code></li>
<li><code>post-merge</code></li>
<li><code>post-rewrite</code></li>
<li><code>pre-commit</code></li>
<li><code>pre-merge-commit</code></li>
<li><code>pre-push</code></li>
<li><code>pre-rebase</code></li>
<li><code>prepare-commit-msg</code></li>
</ul></dd><dt id="prek-util-init-template-dir--log-file"><a href="#prek-util-init-template-dir--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
</dd><dt id="prek-util-init-template-dir--no-allow-missing-config"><a href="#prek-util-init-template-dir--no-allow-missing-config"><code>--no-allow-missing-config</code></a></dt><dd><p>Assume cloned repos should have a <code>pre-commit</code> config</p>
</dd><dt id="prek-util-init-template-dir--no-progress"><a href="#prek-util-init-template-dir--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
<p>For example, spinners or progress bars.</p>
</dd><dt id="prek-util-init-template-dir--quiet"><a href="#prek-util-init-template-dir--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-util-init-template-dir--refresh"><a href="#prek-util-init-template-dir--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
</dd><dt id="prek-util-init-template-dir--verbose"><a href="#prek-util-init-template-dir--verbose"><code>--verbose</code></a>, <code>-v</code></dt><dd><p>Use verbose output</p>
</dd><dt id="prek-util-init-template-dir--version"><a href="#prek-util-init-template-dir--version"><code>--version</code></a>, <code>-V</code></dt><dd><p>Display the prek version</p>
</dd></dl>
## prek self
`prek` self management
+1 -1
View File
@@ -918,7 +918,7 @@ File-type filters based on [`identify`](https://pre-commit.com/#filtering-files-
!!! tip
Use [`prek identify <path>`](cli.md#prek-identify) to see how prek tags a file when you’re troubleshooting `types` filters.
Use [`prek util identify <path>`](cli.md#prek-util-identify) to see how prek tags a file when you’re troubleshooting `types` filters.
Compared to regex-only filtering (`files` / `exclude`), tag-based filtering is often easier and more robust: