Skip to content

fix(find): accept native find flags (-name, -type, etc.)#211

Open
sahilmgandhi wants to merge 1 commit intortk-ai:masterfrom
sahilmgandhi:fix/find-positional-args
Open

fix(find): accept native find flags (-name, -type, etc.)#211
sahilmgandhi wants to merge 1 commit intortk-ai:masterfrom
sahilmgandhi:fix/find-positional-args

Conversation

@sahilmgandhi
Copy link

@sahilmgandhi sahilmgandhi commented Feb 18, 2026

Summary

  • rtk find . -name "*.rs" -type f fails with unexpected argument '-n' found because Clap decomposes -name into short flags (-n, -a, -m, -e) and -n is not defined
  • Changed Find to use trailing_var_arg = true, allow_hyphen_values = true (consistent with Grep, Ls, Tree, and most other RTK commands)
  • Added parse_find_args() that detects and handles both native find syntax (-name, -type, -maxdepth, -iname) and existing RTK syntax (rtk find *.rs src -m 50 -t f)
  • Rejects unsupported compound predicates (-not, -exec, -delete, etc.) with a clear error instead of silently giving wrong results

Changes

File Change
src/main.rs Replaced named Find args with trailing_var_arg + dispatch to run_from_args()
src/find_cmd.rs Added parse_find_args() with native/RTK syntax detection, FindArgs with Default, next_arg helper. Fixed -maxdepth to wire to WalkBuilder::max_depth (traversal depth, not display limit). -iname now performs case-insensitive glob matching. Unsupported flags (-not, -exec, etc.) bail with clear error. 15 new tests.

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets clean
  • cargo test find_cmd — 27/27 tests pass (15 new)
  • cargo test --all — 409/409 tests pass
  • Manual test: rtk find . -name "*.rs" -type f — works, returns compact output
📁 58F 4D:

src/ cargo_cmd.rs cc_economics.rs ccusage.rs config.rs container.rs curl_cmd.rs deps.rs diff_cmd.rs display_helpers.rs env_cmd.rs filter.rs find_cmd.rs format_cmd.rs gain.rs gh_cmd.rs git.rs go_cmd.rs golangci_cmd.rs grep_cmd.rs hook_audit_cmd.rs init.rs json_cmd.rs lint_cmd.rs local_llm.rs log_cmd.rs ls.rs main.rs next_cmd.rs npm_cmd.rs pip_cmd.rs playwright_cmd.rs pnpm_cmd.rs prettier_cmd.rs prisma_cmd.rs pytest_cmd.rs read.rs ruff_cmd.rs runner.rs summary.rs tee.rs tracking.rs tree.rs tsc_cmd.rs utils.rs vitest_cmd.rs wc_cmd.rs wget_cmd.rs
src/discover/ mod.rs provider.rs registry.rs

Copy link
Collaborator

@pszymkowiak pszymkowiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Clean approach, consistent with how we handle git.rs and grep_cmd.rs (trailing_var_arg + manual parsing). Auto-detection of native vs RTK syntax is smart.

15 new tests, security is fine (-exec properly rejected), -iname and -maxdepth are good additions.

One thing to fix before merge:

In parse_native_find_args(), unknown flags are silently swallowed by the _ => {} catch-all. This means rtk find . -mindepth 2 -name "*.rs" succeeds but ignores -mindepth — the user thinks it works but gets wrong results.

Please add a warning on stderr for unknown flags:

_ => {
    eprintln!("rtk find: unknown flag '{}', ignored", args[i]);
}

This way users know their flag was dropped instead of getting silently wrong results.

Everything else looks good — small fix and we can merge 👍

@pszymkowiak
Copy link
Collaborator

Thanks for this PR! Clean approach, consistent with how we handle git.rs and grep_cmd.rs (trailing_var_arg + manual parsing). Auto-detection of native vs RTK syntax is smart.

Tests are solid (15 new), security is fine (-exec properly rejected), and -iname / -maxdepth are nice additions.

One thing to fix before merge: in parse_native_find_args(), unknown flags are silently swallowed by the _ => {} catch-all. I tested with -mindepth and it succeeds without warning — the
user thinks it works but gets wrong results.

_ => {
eprintln!("rtk find: unknown flag '{}', ignored", args[i]);
}

Small fix and we can merge — thanks again!

@sahilmgandhi sahilmgandhi force-pushed the fix/find-positional-args branch from 480d278 to 7a4b64c Compare February 19, 2026 17:50
@sahilmgandhi
Copy link
Author

Thank you for the review @pszymkowiak, I took a pass at it, and updated the PR accordingly.

@aros3rg3d
Copy link

Thanks! It close #170 as well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments