Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions crates/prek/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ pub(crate) struct GlobalArgs {

#[derive(Debug, Subcommand)]
pub(crate) enum Command {
/// Install prek Git shims into Git's effective hooks directory.
/// Install prek Git hook shims.
///
/// By default this is `.git/hooks/`, but repo-local or worktree-local
/// `core.hooksPath` is honored when set.
/// The effective hooks directory defaults to `.git/hooks/`, but repo-local
/// or worktree-local `core.hooksPath` is honored when set.
///
/// The Git shims installed by this command are determined by `--hook-type`
/// or `default_install_hook_types` in the config file, falling back to
Expand All @@ -251,30 +251,30 @@ pub(crate) enum Command {
/// A hook's `stages` field does not affect which Git shims this
/// command installs.
Install(InstallArgs),
/// Prepare environments for all hooks used in the config file.
/// Prepare environments for configured hooks.
///
/// This command does not install Git shims. To install the Git shims
/// along with the hook environments in one command, use `prek install --prepare-hooks`.
#[command(alias = "install-hooks")]
PrepareHooks(PrepareHooksArgs),
/// Run hooks.
/// Run configured hooks.
Run(Box<RunArgs>),
/// List hooks configured in the current workspace.
/// List configured hooks.
List(ListArgs),
/// Uninstall prek Git shims.
/// Uninstall prek Git hook shims.
Uninstall(UninstallArgs),
/// Validate configuration files (prek.toml or .pre-commit-config.yaml).
/// Validate prek configuration files.
ValidateConfig(ValidateConfigArgs),
/// Validate `.pre-commit-hooks.yaml` files.
/// Validate pre-commit hook manifests (`.pre-commit-hooks.yaml`).
ValidateManifest(ValidateManifestArgs),
/// Produce a sample configuration file (prek.toml or .pre-commit-config.yaml).
/// Generate a sample prek configuration file.
SampleConfig(SampleConfigArgs),
/// Update the `rev` field of repositories in the config file to the latest version.
#[command(name = "update", aliases = ["auto-update", "autoupdate"])]
/// Update configured repositories.
#[command(aliases = ["auto-update", "autoupdate"])]
Update(UpdateArgs),
/// Manage the prek cache.
Cache(CacheNamespace),
/// Clean unused cached repos.
/// Remove unused cached repositories, hook environments, and other data.
#[command(hide = true)]
GC(CacheGcArgs),
/// Remove all prek cached data.
Expand All @@ -283,14 +283,14 @@ pub(crate) enum Command {
/// Install Git shims in a directory intended for use with `git config init.templateDir`.
#[command(alias = "init-templatedir", hide = true)]
InitTemplateDir(InitTemplateDirArgs),
/// Try the pre-commit hooks in the current repo.
/// Try hooks from a repository.
TryRepo(Box<TryRepoArgs>),
/// The implementation of the prek Git shim that is installed in Git's effective hooks directory.
#[command(hide = true)]
HookImpl(HookImplArgs),
/// Utility commands.
/// Run utility commands.
Util(UtilNamespace),
/// `prek` self management.
/// Manage the prek installation.
#[command(name = "self")]
Self_(SelfNamespace),
}
Expand Down
19 changes: 6 additions & 13 deletions crates/prek/src/cli/run/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::rc::Rc;
use std::sync::{Arc, LazyLock};

use anyhow::{Context, Result};
use futures_util::stream::{FuturesUnordered, StreamExt};
use futures_util::TryStreamExt;
use futures_util::stream::FuturesUnordered;
use mea::semaphore::Semaphore;
use owo_colors::OwoColorize;
use prek_consts::env_vars::{EnvVars, EnvVarsRead};
Expand Down Expand Up @@ -651,7 +652,7 @@ impl<'a> HookRunSession<'a> {
clean_baseline: bool,
) -> Result<Vec<ProjectRunResult<'project>>> {
let semaphore = Rc::new(Semaphore::new(*HOOK_CONCURRENCY));
let mut runs = FuturesUnordered::new();
let runs = FuturesUnordered::new();
for (idx, project_run) in project_runs.into_iter().enumerate() {
let semaphore = Rc::clone(&semaphore);
runs.push(async move {
Expand All @@ -666,11 +667,7 @@ impl<'a> HookRunSession<'a> {
});
}

let mut results = Vec::new();
while let Some(result) = runs.next().await {
results.push(result?);
}

let mut results: Vec<_> = runs.try_collect().await?;
results.sort_unstable_by_key(|(idx, _)| *idx);
Ok(results.into_iter().map(|(_, result)| result).collect())
}
Expand Down Expand Up @@ -768,7 +765,7 @@ impl<'a> HookRunSession<'a> {
group_hooks.iter().map(|hook| &hook.id).collect::<Vec<_>>()
);

let mut runs = FuturesUnordered::new();
let runs = FuturesUnordered::new();
for hook in group_hooks {
runs.push(run_hook(
hook,
Expand All @@ -781,11 +778,7 @@ impl<'a> HookRunSession<'a> {
));
}

let mut group_results = Vec::new();
while let Some(result) = runs.next().await {
group_results.push(result?);
}
Ok(group_results)
runs.try_collect().await
}

fn update_live_priority_group(&self, group: &ProjectGroupRunResult) {
Expand Down
24 changes: 12 additions & 12 deletions crates/prek/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3246,19 +3246,19 @@ fn selectors_completion() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
install Install prek Git shims into Git's effective hooks directory
prepare-hooks Prepare environments for all hooks used in the config file
run Run hooks
list List hooks configured in the current workspace
uninstall Uninstall prek Git shims
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 configuration file (prek.toml or .pre-commit-config.yaml)
update Update the `rev` field of repositories in the config file to the latest version
install Install prek Git hook shims
prepare-hooks Prepare environments for configured hooks
run Run configured hooks
list List configured hooks
uninstall Uninstall prek Git hook shims
validate-config Validate prek configuration files
validate-manifest Validate pre-commit hook manifests (`.pre-commit-hooks.yaml`)
sample-config Generate a sample prek configuration file
update Update configured repositories
cache Manage the prek cache
try-repo Try the pre-commit hooks in the current repo
util Utility commands
self `prek` self management
try-repo Try hooks from a repository
util Run utility commands
self Manage the prek installation
app/
app:
app-hook App Hook
Expand Down
50 changes: 25 additions & 25 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ 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 prek Git shims into Git's effective hooks directory</p></dd>
<dt><a href="#prek-prepare-hooks"><code>prek prepare-hooks</code></a></dt><dd><p>Prepare 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 hooks configured in the current workspace</p></dd>
<dt><a href="#prek-uninstall"><code>prek uninstall</code></a></dt><dd><p>Uninstall prek Git shims</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 configuration file (prek.toml or .pre-commit-config.yaml)</p></dd>
<dt><a href="#prek-update"><code>prek update</code></a></dt><dd><p>Update the <code>rev</code> field of repositories in the config file to the latest version</p></dd>
<dl class="cli-reference"><dt><a href="#prek-install"><code>prek install</code></a></dt><dd><p>Install prek Git hook shims</p></dd>
<dt><a href="#prek-prepare-hooks"><code>prek prepare-hooks</code></a></dt><dd><p>Prepare environments for configured hooks</p></dd>
<dt><a href="#prek-run"><code>prek run</code></a></dt><dd><p>Run configured hooks</p></dd>
<dt><a href="#prek-list"><code>prek list</code></a></dt><dd><p>List configured hooks</p></dd>
<dt><a href="#prek-uninstall"><code>prek uninstall</code></a></dt><dd><p>Uninstall prek Git hook shims</p></dd>
<dt><a href="#prek-validate-config"><code>prek validate-config</code></a></dt><dd><p>Validate prek configuration files</p></dd>
<dt><a href="#prek-validate-manifest"><code>prek validate-manifest</code></a></dt><dd><p>Validate pre-commit hook manifests (<code>.pre-commit-hooks.yaml</code>)</p></dd>
<dt><a href="#prek-sample-config"><code>prek sample-config</code></a></dt><dd><p>Generate a sample prek configuration file</p></dd>
<dt><a href="#prek-update"><code>prek update</code></a></dt><dd><p>Update configured repositories</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-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>
<dt><a href="#prek-try-repo"><code>prek try-repo</code></a></dt><dd><p>Try hooks from a repository</p></dd>
<dt><a href="#prek-util"><code>prek util</code></a></dt><dd><p>Run utility commands</p></dd>
<dt><a href="#prek-self"><code>prek self</code></a></dt><dd><p>Manage the prek installation</p></dd>
</dl>

## prek install

Install prek Git shims into Git's effective hooks directory.
Install prek Git hook shims.

By default this is `.git/hooks/`, but repo-local or worktree-local `core.hooksPath` is honored when set.
The effective hooks directory defaults to `.git/hooks/`, but repo-local or worktree-local `core.hooksPath` is honored when set.

The Git shims installed by this command are determined by `--hook-type` or `default_install_hook_types` in the config file, falling back to `pre-commit` when neither is set.

Expand Down Expand Up @@ -119,7 +119,7 @@ prek install [OPTIONS] [HOOK|PROJECT]...

## prek prepare-hooks

Prepare environments for all hooks used in the config file.
Prepare environments for configured hooks.

This command does not install Git shims. To install the Git shims along with the hook environments in one command, use `prek install --prepare-hooks`.

Expand Down Expand Up @@ -184,7 +184,7 @@ prek prepare-hooks [OPTIONS] [HOOK|PROJECT]...

## prek run

Run hooks
Run configured hooks

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -279,7 +279,7 @@ prek run [OPTIONS] [HOOK|PROJECT]...

## prek list

List hooks configured in the current workspace
List configured hooks

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -392,7 +392,7 @@ prek list [OPTIONS] [HOOK|PROJECT]...

## prek uninstall

Uninstall prek Git shims
Uninstall prek Git hook shims

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -442,7 +442,7 @@ prek uninstall [OPTIONS]

## prek validate-config

Validate configuration files (prek.toml or .pre-commit-config.yaml)
Validate prek configuration files

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -478,7 +478,7 @@ prek validate-config [OPTIONS] [CONFIG]...

## prek validate-manifest

Validate `.pre-commit-hooks.yaml` files
Validate pre-commit hook manifests (`.pre-commit-hooks.yaml`)

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -514,7 +514,7 @@ prek validate-manifest [OPTIONS] [MANIFEST]...

## prek sample-config

Produce a sample configuration file (prek.toml or .pre-commit-config.yaml)
Generate a sample prek configuration file

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -552,7 +552,7 @@ prek sample-config [OPTIONS]

## prek update

Update the `rev` field of repositories in the config file to the latest version
Update configured repositories

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -747,7 +747,7 @@ prek cache size [OPTIONS]

## prek try-repo

Try the pre-commit hooks in the current repo
Try hooks from a repository

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -840,7 +840,7 @@ prek try-repo [OPTIONS] <REPO> [HOOK|PROJECT]...

## prek util

Utility commands
Run utility commands

<h3 class="cli-reference">Usage</h3>

Expand Down Expand Up @@ -1025,7 +1025,7 @@ prek util yaml-to-toml [OPTIONS] [CONFIG]

## prek self

`prek` self management
Manage the prek installation

<h3 class="cli-reference">Usage</h3>

Expand Down
Loading