find: add -warn and -nowarn options - #839
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #839 +/- ##
==========================================
+ Coverage 92.15% 92.34% +0.19%
==========================================
Files 35 35
Lines 7377 7501 +124
Branches 383 392 +9
==========================================
+ Hits 6798 6927 +129
+ Misses 438 432 -6
- Partials 141 142 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Commit 5e14879 has test result changes: bfs testsuite: |
There was a problem hiding this comment.
Pull request overview
This PR adds GNU-compatible warning-mode handling to find, introducing -warn/-nowarn to toggle warnings during expression parsing and emitting a GNU-style diagnostic when a supported global option (e.g., -maxdepth) appears after a test/action.
Changes:
- Track warning state and the most recent test/action during matcher-tree construction to support positional
-warn/-nowarn. - Emit a “misplaced global option” warning when warnings are enabled and a global option follows a prior test/action.
- Add an integration test covering enabling the diagnostic and disabling it before parsing the global option.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_find.rs | Adds coverage for the warning emission and for suppressing it via -nowarn. |
| src/find/mod.rs | Initializes default warning state based on stdin TTY + POSIXLY_CORRECT, and documents -warn/-nowarn in help text. |
| src/find/matchers/mod.rs | Implements -warn/-nowarn, tracks last test/action, and emits the global-option ordering warning. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| fn is_global_option(argument: &str) -> bool { | ||
| matches!( | ||
| argument, | ||
| "-d" | "-depth" | ||
| | "-files0-from" | ||
| | "-help" | ||
| | "--help" | ||
| | "-maxdepth" | ||
| | "-mindepth" | ||
| | "-mount" | ||
| | "-xdev" | ||
| | "-noleaf" | ||
| | "-sorted" | ||
| | "-version" | ||
| | "--version" | ||
| ) | ||
| } |
| eprintln!( | ||
| "find: warning: you have specified the global option {argument} after the \ | ||
| argument {previous}, but global options are not positional, i.e., {argument} \ | ||
| affects tests specified before it as well as those specified after it. Please \ | ||
| specify global options before other arguments." | ||
| ); |
5e14879 to
546d204
Compare
|
Commit 546d204 has test result changes: bfs testsuite: |
GNU find distinguishes warnings about inadvisable command-line usage from errors encountered while traversing directories. These warnings do not change find's exit status. By default, GNU enables them only when standard input is a terminal and POSIXLY_CORRECT is unset; otherwise it disables them so existing scripts do not gain unsolicited diagnostics. The -warn and -nowarn options change that state at the point where each appears. Thus `-warn -type d -maxdepth 1` warns when parsing reaches -maxdepth, while placing -nowarn before -maxdepth suppresses the warning. Putting -nowarn at the end cannot retract a warning already emitted. GNU leaves the active warnings unspecified when POSIXLY_CORRECT and an explicit -warn are both present. Global options such as -maxdepth are semantically non-positional: they affect tests before and after their location. GNU accepts a global option after a test or action, but warns that the ordering is misleading when warnings are enabled. uutils previously rejected -warn and -nowarn as unknown predicates. Track the current warning state and most recent test or action, accept both options, and implement GNU's misplaced-global-option diagnostic for the supported global options. Do not issue that diagnostic for help or version options: they terminate parsing instead of affecting surrounding tests, so the diagnostic's explanation would be false. GNU also controls warnings for deprecated -d and slashes in -name or -iname patterns; those remain outside this change. Adding -warn also enables an external compatibility test which exposes an unsafe interaction with -execdir and -okdir. Those actions change directory before searching PATH for the requested executable, so a relative or empty PATH entry can select a different program in each visited directory. Reject non-absolute PATH entries when parsing either action. Add coverage for enabling the diagnostic, disabling it before the global option is parsed, excluding the terminating help and version options, and rejecting relative PATH entries for directory-local actions.
546d204 to
4f58b49
Compare
|
The latest change should have fixed the test suite issues. Github is having some problems, so not clear the automation will run correctly. |
|
could you please fix the conflict? thanks |
| Ok(file) | ||
| } | ||
|
|
||
| fn is_global_option(argument: &str) -> bool { |
There was a problem hiding this comment.
what is a global option?
There was a problem hiding this comment.
Added a doc explaining what this means (it's a GNU term)
Address PR feedback asking for clarification on is_global_option.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/find/mod.rs:31
last_non_optionis used to store the most recent test/action token for the misplaced-global-option warning, not the “last non-option” in the traditional CLI sense. Renaming this field (and the related helperis_testing_criterion) to reflect its actual meaning would make the warning logic easier to understand and maintain.
no_leaf_dirs: bool,
warnings_enabled: bool,
last_non_option: Option<String>,
src/find/matchers/mod.rs:472
is_global_optionomits-follow, but-followmutatesconfig.followin a way that affects traversal and matchers globally (i.e., it is also non-positional in this implementation). As a result,-warn -type f -followwon’t emit the same misplaced-global-option warning that-maxdepth/-mindepthdo. Consider including-followin the global-option set (and therefore making it warnable) for consistency with the “global options are not positional” diagnostic.
fn is_global_option(argument: &str) -> bool {
matches!(
argument,
"-d" | "-depth"
| "-files0-from"
GNU find distinguishes warnings about inadvisable command-line usage from errors encountered while traversing directories. These warnings do not change find's exit status. By default, GNU enables them only when standard input is a terminal and POSIXLY_CORRECT is unset; otherwise it disables them so existing scripts do not gain unsolicited diagnostics.
The -warn and -nowarn options change that state at the point where each appears. Thus
-warn -type d -maxdepth 1warns when parsing reaches -maxdepth, while placing -nowarn before -maxdepth suppresses the warning. Putting -nowarn at the end cannot retract a warning already emitted. GNU leaves the active warnings unspecified when POSIXLY_CORRECT and an explicit -warn are both present.Global options such as -maxdepth are semantically non-positional: they affect tests before and after their location. GNU accepts a global option after a test or action, but warns that the ordering is misleading when warnings are enabled.
uutils previously rejected -warn and -nowarn as unknown predicates. Track the current warning state and most recent test or action, accept both options, and implement GNU's misplaced-global-option diagnostic for the supported global options. GNU also controls warnings for deprecated -d and slashes in -name or -iname patterns; those remain outside this change.
Add coverage for enabling the diagnostic and disabling it before the global option is parsed.