Skip to content

feat(search): add --all and --jq flags - #87

Open
Aidan Holland (thehappydinoa) wants to merge 2 commits into
mainfrom
feat/search-improvements
Open

Aidan Holland (thehappydinoa) wants to merge 2 commits into
mainfrom
feat/search-improvements

Conversation

@thehappydinoa

Copy link
Copy Markdown
Member

Summary

  • --all / -A: fetches all pages of results without triggering the --max-pages=-1 deprecation warning; suppressed in --count mode
  • --jq <expr>: filters output using a minimal jq-style path evaluator (internal/pkg/jq) — no new dependencies
  • New package internal/pkg/jq with Parse, Eval, EvalJSON, and FormatValue; mirrors jq -r output (strings unquoted, objects as compact JSON)

Details

--all

  • Equivalent to --max-pages=-1 but cleaner UX — skips the "fetching all pages" warning that fires when max-pages is not set
  • Added to the warnIgnoredCountFlags list alongside --jq

--jq

  • Validated at PreRun time (bad expression → early error before any API calls)
  • Supported syntax: . (identity), .field, .field.sub, .field[], .[], and combinations
  • Data is wrapped as {"host": {...}} by prepareSearchData(), so natural expressions like .host.ip and .host.services[].port work out of the box
  • Zero new dependencies — pure stdlib (encoding/json, strings, fmt)

Test plan

  • internal/pkg/jq unit tests cover: identity, field access, nested fields, array expansion, missing fields, FormatValue, and invalid expression error
  • E2E golden file updated for search --help
  • --all and --jq added to warnIgnoredCountFlags coverage
  • Manual: censys search --all "host.services.protocol=SSH" fetches multiple pages without warning
  • Manual: censys search --jq .host.ip "host.services.protocol=SSH" prints one IP per line
  • Manual: censys search --all --jq ".host.services[].port" "host.location.country: Germany" expands services across all pages

🤖 Generated with Claude Code

--all (-A): fetches all pages without the --max-pages=-1 warning; suppressed in --count mode.

--jq <expr>: filters output using a minimal stdlib-only jq-style path evaluator.
  Supported: .field, .field.sub, .field[], .[], and combinations.
  Output mirrors jq -r: strings print unquoted, complex types as compact JSON.
  Expression is validated at PreRun time. Ignored in --count mode.

New package internal/pkg/jq with Parse, Eval, EvalJSON, and FormatValue.
No new dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cobra pads wrapped description lines to the detected terminal width on
Linux, producing trailing spaces mid-output. assertGoldenFile previously
only trimmed the trailing end of the whole output; now each line is also
right-trimmed before comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant