diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c4d2d..3e77639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +- `query --include-full-path` flag to include absolute file path in JSON output - Plugin system: executables named `tk-` or `ticket-` in PATH are invoked automatically - `super` command to bypass plugins and run built-in commands directly - `TICKETS_DIR` and `TK_SCRIPT` environment variables exported for plugins diff --git a/README.md b/README.md index 8b069ef..4eac597 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,8 @@ Commands: show Display ticket edit Open ticket in $EDITOR add-note [text] Append timestamped note (or pipe via stdin) - query [jq-filter] Output tickets as JSON, optionally filtered + query [options] [jq-filter] Output tickets as JSON, optionally filtered + --include-full-path Include absolute file path in each JSON object migrate-beads Import tickets from .beads/issues.jsonl super [args] Bypass plugins, run built-in command directly diff --git a/features/ticket_query.feature b/features/ticket_query.feature index 2ccafe7..f883d91 100644 --- a/features/ticket_query.feature +++ b/features/ticket_query.feature @@ -46,3 +46,27 @@ Feature: Ticket Query When I run "ticket query" Then the command should succeed And the JSONL deps field should be a JSON array + + Scenario: Query with --include-full-path includes file path + Given a ticket exists with ID "query-001" and title "Path ticket" + When I run "ticket query --include-full-path" + Then the command should succeed + And the output should be valid JSONL + And the JSONL output should have field "full_path" + And the output should contain "query-001.md" + + Scenario: Query with --include-full-path and jq filter + Given a ticket exists with ID "query-001" and title "Open path ticket" + And a ticket exists with ID "query-002" and title "Closed path ticket" + And ticket "query-002" has status "closed" + When I run "ticket query --include-full-path '.status == \"open\"'" + Then the command should succeed + And the JSONL output should have field "full_path" + And the output should contain "query-001" + And the output should not contain "query-002" + + Scenario: Query without --include-full-path excludes file path + Given a ticket exists with ID "query-001" and title "No path ticket" + When I run "ticket query" + Then the command should succeed + And the output should not contain "full_path" diff --git a/ticket b/ticket index 1dedcec..9666cd5 100755 --- a/ticket +++ b/ticket @@ -1319,11 +1319,17 @@ cmd_edit() { } cmd_query() { - local filter="${1:-}" + local filter="" include_full_path=0 + while [[ $# -gt 0 ]]; do + case "$1" in + --include-full-path) include_full_path=1; shift ;; + *) filter="$1"; shift ;; + esac + done # Generate all JSON in one awk pass local json_output - json_output=$(awk ' + json_output=$(awk -v include_path="$include_full_path" ' BEGIN { FS=": "; in_front=0 } FNR==1 { if (prev_file) emit() @@ -1361,6 +1367,9 @@ cmd_query() { printf "\"%s\":\"%s\"", key, val } } + if (include_path == 1) { + printf ",\"full_path\":\"%s\"", prev_file + } printf "}\n" } } @@ -1502,7 +1511,8 @@ Commands: show Display ticket edit Open ticket in \$EDITOR add-note [text] Append timestamped note (or pipe via stdin) - query [jq-filter] Output tickets as JSON, optionally filtered + query [options] [jq-filter] Output tickets as JSON, optionally filtered + --include-full-path Include absolute file path in each JSON object migrate-beads Import tickets from .beads/issues.jsonl super [args] Bypass plugins, run built-in command directly EOF