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

Support pass multiple files like prek run --files a b c d (#828)

This commit is contained in:
Nyakku Shigure
2025-10-01 19:32:27 +08:00
committed by GitHub
parent 1e9ccf01f4
commit 7b8cb627bd
2 changed files with 36 additions and 0 deletions
+1
View File
@@ -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<String>,
+35
View File
@@ -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<()> {