Repository navigation
Accept -e/-f patterns without a positional pattern in search - #232
Merged
Shengyu Fu (shengyfu) merged 1 commit intoNov 30, 2026
Merged
Conversation
`tgrep search -e foo` and `tgrep search -f patterns` failed with "the following required arguments were not provided: <PATTERN>" when no path was given, although the top-level form and ripgrep accept them. The subcommand's positional pattern was a required String, so clap demanded it before -e/-f were considered. Make it optional and require it only when no -e/-f pattern was given in any command scope, after the scopes are merged, so a parent command's patterns (`tgrep -e foo search`) count too.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the changes allowing search to use -e/-f patterns without a positional pattern.
No open issues 🎉
What changed in this PR
This PR aligns the search subcommand with tgrep’s top-level behavior, allowing -e/-f patterns without a positional pattern while still rejecting searches with no pattern source.
Changes:
- Makes the positional pattern optional and validates it after global argument scopes are merged.
- Passes the optional pattern through the existing pattern/path splitting logic.
- Adds unit and integration tests for flags before and after
search, path handling, and missing-pattern errors.
| File | Description |
|---|---|
tgrep-cli/tests/ripgrep_compat.rs |
Adds CLI regression tests for pattern-source flags and bare search errors. |
tgrep-cli/src/main.rs |
Updates pattern parsing and validation, with unit tests for argument handling. |
Review effort: Balanced
Contributor
Author
|
@microsoft-github-policy-service agree |
Shengyu Fu (shengyfu)
approved these changes
Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
searchsubcommand rejects-e/-fpatterns when no path follows:rg -e fooandrg -f pats(ripgrep 14.1.1) search the current directory, and so does tgrep's top-level form. With a path (tgrep search -e foo .) the subcommand already works, because the path is first parsed as the pattern and then moved back to the paths bysplit_pattern_and_paths.Cause: in
Command::Searchthe positionalpatternis a requiredString, so clap demands it before-e/-fare taken into account. The top-levelpatternis already anOption<String>.Change: make the
searchpattern anOption<String>and pass it tosplit_pattern_and_pathsas the top-level form does. The pattern is still required when no-e/-fpattern is given; that check runs intry_parse_args_fromafter the command scopes are merged, because-e/-fare global and a parent command's patterns (tgrep -e foo search) must count as well. Clap validates each scope on its own, sorequired_unless_present_anyon the subcommand would not see them.tgrep searchwith no pattern still fails with the same "required arguments" error and exit code 2.Tests:
search_subcommand_accepts_patterns_from_regexp_or_file_without_positionalintgrep-cli/tests/ripgrep_compat.rsrunssearch -e foo,search -f <file>,-e foo searchand-f <file> searchin a directory and checks the match, and checks that a baresearchstill exits 2 naming<PATTERN>. It fails without the change (exit 2) and passes with it.search_subcommand_pattern_is_optional_with_regexp_or_fileinmain.rschecks the parsed pattern/paths split for these forms, with and without paths, and the missing-pattern error kind.cargo fmt --all -- --checkis clean.cargo clippy --locked --workspace --all-targets --features tgrep-cli/managed-test-hooks -- -D warningsreports only twononminimal_boolerrors inserve.rsandserve/shared/managed.rs, which this change does not touch (same onmainwith Rust 1.93.1 and 1.95); it is otherwise clean.cargo test --locked --workspace --features tgrep-cli/managed-test-hooks -- --test-threads=2:ripgrep_compat270 passed,ripgrep_parity102 passed. The managed/shared-index tests fail on my machine because its Git 2.34 lacksgit worktree list -z; the same 250 tests fail onmainthere.