From 7b8cb627bdbf295b4eecd39cf3f09661fd66c20c Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Wed, 1 Oct 2025 19:32:27 +0800 Subject: [PATCH] Support pass multiple files like `prek run --files a b c d` (#828) --- src/cli/mod.rs | 1 + tests/run.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ec2dbb34..89a0cb50 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -402,6 +402,7 @@ pub(crate) struct RunArgs { #[arg( long, conflicts_with_all = ["all_files", "from_ref", "to_ref"], + num_args = 1.., value_hint = ValueHint::AnyPath) ] pub(crate) files: Vec, diff --git a/tests/run.rs b/tests/run.rs index a9144d5b..8072dcee 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -1315,6 +1315,41 @@ fn run_last_commit() -> Result<()> { Ok(()) } +/// Test `prek run --files` with multiple files. +#[test] +fn run_multiple_files() -> Result<()> { + let context = TestContext::new(); + context.init_project(); + context.write_pre_commit_config(indoc::indoc! {r" + repos: + - repo: local + hooks: + - id: multiple-files + name: multiple-files + language: system + entry: echo + verbose: true + types: [text] + "}); + let cwd = context.work_dir(); + cwd.child("file1.txt").write_str("Hello, world!")?; + cwd.child("file2.txt").write_str("Hello, world!")?; + context.git_add("."); + // multiple `--files` + cmd_snapshot!(context.filters(), context.run().arg("--files").arg("file1.txt").arg("file2.txt"), @r#" + success: true + exit_code: 0 + ----- stdout ----- + multiple-files...........................................................Passed + - hook id: multiple-files + - duration: [TIME] + file2.txt file1.txt + + ----- stderr ----- + "#); + Ok(()) +} + /// Test `prek run --directory` flags. #[test] fn run_directory() -> Result<()> {