Skip to content

feat(search): add tsk search command for fuzzy CLI search#7

Closed
Sanjays2402 wants to merge 2 commits into
feat/ls-tablefrom
feat/cli-search
Closed

feat(search): add tsk search command for fuzzy CLI search#7
Sanjays2402 wants to merge 2 commits into
feat/ls-tablefrom
feat/cli-search

Conversation

@Sanjays2402

Copy link
Copy Markdown
Owner

The TUI has had instant fuzzy search since v0.1. The CLI has been blind: once a project has >20 tasks, finding one means scrolling ls output manually.

This adds the same search affordance to scripts and one-shots.

Examples

$ tsk search milk
[ ] #3 buy milk  (medium)

$ tsk search "fix login" --limit 5
[ ] #12 fix login bug  (high)
[ ] #7 add login telemetry  (medium)

$ tsk search dev --all --format table
ID  DONE  P  DUE  TITLE                  TAGS
#1  [x]   H       ship table format PR   #dev
#5  [ ]   M       review v0.3.0 release  #dev

$ tsk search docs --json | jq '.[].Title'

Implementation

  • Reuses internal/util/fuzzy (sahilm/fuzzy) — same scoring the TUI uses, so CLI and TUI rank results identically
  • Default index: title + #tag1 #tag2 + notes
  • --title-only restricts matching to titles
  • Filter: undone by default; --done for done only; --all for both
  • --limit N caps results
  • --format plain | table | json (table reuses the renderer from feat(ls): add --format=table with aligned columns #6)
  • --json shortcut preserved, mutually exclusive with --format
  • Empty result: no matches for <q> in text mode, [] in JSON mode

Tests

10 cases in search_test.go:

  1. Title match
  2. Tag match (default index)
  3. --title-only skips tags
  4. Done filtered out by default
  5. --all includes done
  6. --limit caps results
  7. --json non-empty
  8. --json empty array
  9. Whitespace-only query rejected
  10. --format=table works

All green with -race.

Stacked on #6

This PR builds on feat/ls-table (PR #6) for the table renderer. Once #6 merges, this PR auto-rebases against main cleanly.

Part 3/10 of the v0.3.0 improvement series.

The TUI has had instant fuzzy search since v0.1. The CLI has been blind:
once a project has >20 tasks, finding one means scrolling `ls` output
manually. This adds the same search affordance to scripts and one-shots.

Implementation:
  - Reuses internal/util/fuzzy (sahilm/fuzzy), same scoring as the TUI
  - Default index: title + #tags + notes
  - --title-only restricts to titles
  - Filter: undone by default, --done | --all
  - --limit N caps results
  - --format plain/table/json (table reuses #6 renderer)
  - --json shortcut preserved, mutually exclusive with --format
  - Empty result: "no matches for <q>" in text, "[]" in JSON

Examples:
  tsk search milk
  tsk search "fix login" --limit 5
  tsk search dev --all
  tsk search docs --json | jq

Tests: 10 cases — title match, tag match, --title-only, done filter,
--all, --limit, --json non-empty, --json empty array, empty query
rejection, table format. All green with -race.
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.

1 participant