Skip to content

feat(completion): __complete subcommand foundation (#291)#312

Merged
erishforG merged 1 commit into
developfrom
feat/291-dynamic-completion-foundation
May 24, 2026
Merged

feat(completion): __complete subcommand foundation (#291)#312
erishforG merged 1 commit into
developfrom
feat/291-dynamic-completion-foundation

Conversation

@erishforG
Copy link
Copy Markdown
Owner

Summary

  • New hidden subcommand: `parsec __complete <worktrees|branches>`
  • Emits newline-separated candidates; silent on failure so completion never errors at the prompt
  • Adds `git::list_local_branches` helper
  • 4 new integration tests (hidden-from-help / branches / worktrees / silent-outside-repo)

Scope of this PR (foundation only)

This is step 1 of 2 for #291. It lands the data-emission half:

```
$ parsec __complete worktrees
PROJ-101
PROJ-102

$ parsec __complete branches
develop
feature/x
main
```

What's NOT in this PR (follow-up)

Step 2 — making the existing `parsec config completions ` output call `__complete` from inside the generated zsh/bash/fish functions. The post-processing approach (replace `_files` with shell-specific `compadd "$(parsec __complete worktrees)"` blocks at known argument positions) belongs in its own PR so this one stays reviewable.

Filing as draft so we can agree on the foundation shape (hidden command name, candidate format, silent-failure policy) before wiring the shell scripts.

Test plan

  • `cargo fmt --all -- --check`
  • `cargo clippy -- -D warnings`
  • `cargo test` — 102/102 pass
  • Manual: `parsec __complete branches` / `parsec __complete worktrees` on this repo

Open questions for review

  1. Hidden subcommand name — `__complete` (cargo-style) vs `_completion` vs nested under `config`?
  2. Should we emit a header like `# worktree-tickets` so shell scripts can sanity-check? (Currently no — keeps parsing trivial.)

Refs: #291

Adds `parsec __complete <worktrees|branches>` — a hidden subcommand that
shell completion scripts can call to enumerate candidates dynamically.
Failure paths (no repo / no config) silently emit nothing so completion
never errors at the prompt.

Also adds `git::list_local_branches`, a helper for enumerating local
branch names via `git for-each-ref refs/heads/`.

This is the **foundation only**. The follow-up work — post-processing
clap-generated completion scripts (zsh/bash/fish) so that ticket-shaped
arguments call `parsec __complete worktrees` and branch-shaped arguments
call `parsec __complete branches` — lands in a separate PR.

Refs: #291
@erishforG
Copy link
Copy Markdown
Owner Author

두 질문에 대한 결정 (현재 코드 유지)

Q1: __complete (cargo style) 유지

  • cargo/gh/rustup 모두 동일 패턴. Rust 생태계 표준이라 즉시 이해됨.
  • shell script 안에서만 호출되니 발견성 낮은 게 장점.
  • config completions(script 생성) vs config complete(값 emit)는 의미가 달라서 같은 그룹에 묶지 않는 게 명확함.

Q2: 헤더 emit 안 함 (현재 그대로)

  • silent-failure 정책이 이미 안전망 역할.
  • 자동완성은 hot path — 파싱은 while read line 한 줄로 끝나는 게 좋음.
  • 잘못된 output 가능성이 낮고, 발생해도 사용자 체감은 "자동완성 안 나옴" 수준 (silent).

→ 코드 변경 없이 ready 전환 + 머지.

@erishforG erishforG marked this pull request as ready for review May 24, 2026 03:33
@erishforG erishforG merged commit 0aa2c0a into develop May 24, 2026
12 checks passed
@erishforG erishforG deleted the feat/291-dynamic-completion-foundation branch May 24, 2026 03:33
erishforG added a commit that referenced this pull request May 25, 2026
…317)

develop에 머지됐지만 CHANGELOG.md [Unreleased]에 누락된
항목 4개를 추가한다:

- parsec smartlog (alias sl): commit DAG 시각화 (#245, #305)
- parsec __complete: 동적 shell completion 헬퍼 (#291, #312)
- 에러 메시지 3줄 표준화 (error/caused by/help) (#303, #306)
- Windows VS2026 pre-validation CI job (#307, #311)

Closes #316

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
erishforG added a commit that referenced this pull request May 30, 2026
…291) (#328)

Phase 1 (#312) 가 `parsec __complete <kind>` 내부 명령을 만들어 shell completion
스크립트가 동적으로 worktree/branch 후보를 가져올 수 있게 했음. 이번에는 그 위에
실제 zsh/bash/fish 스크립트 3개를 추가해서 사용자가 sourcing 만 하면
`parsec switch <Tab>` 처럼 live ticket 자동완성을 받을 수 있게 함.

## 변경
- `completions/_parsec` (zsh, #compdef) — `_parsec_worktrees` / `_parsec_branches`
  helper + 모든 주요 subcommand 의 positional/option 자동완성
- `completions/parsec.bash` — `complete -F _parsec parsec`. bash-completion
  의존 (`_init_completion`). prev word 기반 dispatch + `compgen -W`
- `completions/parsec.fish` — `__fish_seen_subcommand_from` 기반.
  per-subcommand 옵션 (`--base`, `--on`, `--branch`) 도 동적 branch/worktree
  후보 연결
- README "Install > Shell completion" 섹션 추가 (3개 shell install 명령)

## 커버 범위 (Tier 1 + 2)
- ticket 받는 subcommand: start, switch, ship, open, clean, status, ticket,
  pr-status, ci, merge, diff, sync, log, compress, adopt, rename
- branch 받는 옵션: `start --base|--on|--branch`, `ship --base`, `adopt --branch`
- smartlog: `--depth`, `--no-overlay` (PR #327 와 호환)

## __complete kind 추가
없음. Phase 1 의 `worktrees` / `branches` 두 개로 충분 — future Phase 3 에서
필요하면 추가 (예: `tickets` 트래커, `reviewers` GitHub 사용자).

## 드라이브-바이
PR #327 에서 같이 잡았던 `tests/cli_tests.rs:1725` clippy 회귀 (#326)
develop 머지 전이라 또 한 번 적용. PR #327 머지되면 충돌 안 남.

## 테스트
- 신규 4개 통합 테스트:
  - `completion_zsh_present_and_dynamic` — `#compdef parsec` + `__complete` 호출 + 핵심 sub 7개
  - `completion_bash_present_and_dynamic` — `complete -F _parsec parsec` + 동일
  - `completion_fish_present_and_dynamic` — `__parsec_worktrees` 함수 + 동일
  - `completion_scripts_reference_phase1_subcommand_signature` — 스크립트가
    Phase 1 가 지원하지 않는 kind 부르지 않는지 (silent fail 방지)
- 전체 62 통합 테스트 + smartlog 14 단위 + health 5 통과
- cargo build / clippy -D warnings / fmt --check 전부 clean

## 다음 Phase 힌트
- Phase 3: `__complete tickets` (트래커 미해결 티켓), `__complete reviewers`
  (GitHub mention)
- Phase 4: shell auto-install hook (parsec init 에서 자동 설치 옵션)

Refs #291

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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