Skip to content

Comments

introduce dynamic filtering#2221

Merged
Mzack9999 merged 5 commits intodevfrom
2103_introduce_dynamic_output_filtering
Sep 3, 2025
Merged

introduce dynamic filtering#2221
Mzack9999 merged 5 commits intodevfrom
2103_introduce_dynamic_output_filtering

Conversation

@dogancanbakir
Copy link
Member

@dogancanbakir dogancanbakir commented Jul 24, 2025

closes #2103

Summary by CodeRabbit

  • New Features
    • Added --list-output-fields (-lof) to print available output field names and exit.
    • Added --exclude-output-fields (-eof) to omit specified fields from results and downstream outputs.
  • Behavior
    • Normal execution unchanged unless these flags are used.
    • Listing fields will print names and exit; if field discovery fails, the command reports an error and exits non-zero.

@dogancanbakir dogancanbakir self-assigned this Jul 24, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

Adds CLI flags to list public Result fields and to exclude specified fields from outputs; when requested, prints Result field names and exits. During enumeration output handling, results are filtered to remove any fields listed in the exclude flag before further processing.

Changes

Cohort / File(s) Summary
CLI options and flags
runner/options.go
Adds ListOutputFields bool and ExcludeOutputFields goflags.StringSlice to Options; wires --list-output-fields (-lof) and --exclude-output-fields (-eof) under Filters; if --list-output-fields set, prints Result public fields via structs.GetStructFields and exits.
Output filtering in enumeration
runner/runner.go
Imports github.com/projectdiscovery/utils/structs; in RunEnumeration output goroutine, when ExcludeOutputFields is non-empty calls structs.FilterStruct(resp, nil, r.options.ExcludeOutputFields) and replaces resp with the filtered result for subsequent handlers (OnResult/JSON/CSV).
Documentation
README.md
Documents new flags --list-output-fields (-lof) and --exclude-output-fields (-eof) under OUTPUT.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI
  participant Parse as ParseOptions
  participant Runner
  participant OutG as Output Goroutine
  participant Structs as structs

  User->>CLI: run with flags
  CLI->>Parse: ParseOptions()
  alt --list-output-fields set
    Parse->>Structs: GetStructFields(Result)
    Structs-->>Parse: field names / error
    Parse-->>User: print fields / exit(0)
  else normal flow
    Parse-->>Runner: options
    Runner->>OutG: emit resp
    alt exclude flags non-empty
      OutG->>Structs: FilterStruct(resp, include=nil, exclude=flags)
      Structs-->>OutG: filtered resp / error
      OutG->>OutG: replace resp with filtered resp
    else no excludes
      OutG->>OutG: keep original resp
    end
    OutG-->>Runner: continue OnResult/JSON/CSV handling
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Prevent unspecified fields from appearing in JSON output by default (#2103) The change makes field exclusion opt-in; default behavior still emits all fields.
Provide a mechanism to control which fields are included/excluded in JSON output (#2103)
Discoverability of available output fields to aid configuration (#2103)

Poem

I nibble code and hop with glee,
Show fields or hide what bugs me,
I prune the output, neat and small,
A tidy burrow — that’s my call. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 65d4f6e and a8a4969.

📒 Files selected for processing (1)
  • README.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Test Builds (macOS-latest)
  • GitHub Check: Test Builds (ubuntu-latest)
  • GitHub Check: Test Builds (windows-latest)
  • GitHub Check: Functional Test (windows-latest)
  • GitHub Check: Functional Test (macOS-latest)
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2103_introduce_dynamic_output_filtering

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 809b888 and dc8ad17.

📒 Files selected for processing (2)
  • runner/options.go (4 hunks)
  • runner/runner.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: release-test
  • GitHub Check: Functional Test (windows-latest)
  • GitHub Check: Functional Test (macOS-latest)
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
runner/options.go (2)

34-34: LGTM: Import addition for struct utilities

The import is correctly added and necessary for the new dynamic filtering functionality.


552-561: LGTM: Well-implemented field listing functionality

The implementation correctly:

  • Checks the flag condition
  • Uses appropriate error handling with fatal exit
  • Provides clean output format
  • Follows the early exit pattern for utility flags
runner/runner.go (1)

44-44: Good addition of the required import.

The new import for the structs utility package is correctly positioned and necessary for the filtering functionality.

@Mzack9999 Mzack9999 merged commit 56c3dc4 into dev Sep 3, 2025
14 checks passed
@Mzack9999 Mzack9999 deleted the 2103_introduce_dynamic_output_filtering branch September 3, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

additional fields in json output thatare not specified.

2 participants