-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add quiet mode to list subcommand #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The --quiet / -q switch for the `list` subcommand provides scripting friendly output to the list subcommand, outputting only the values from the "PATH" column of the pre-existing output.
WalkthroughAdds a quiet mode flag (--quiet / -q) to the list command, extends listCommandWithCommandExecutor to accept a quiet bool, introduces getWorktreeDisplayName and displayWorktreesQuiet helpers, and updates tests to exercise quiet-mode outputs. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI
participant ListCmd as listCommandWithCommandExecutor
participant Executor as command.Executor
participant DisplayQuiet as displayWorktreesQuiet
participant DisplayRel as displayWorktreesRelative
participant NameHelper as getWorktreeDisplayName
CLI->>ListCmd: invoke list (with flags incl. quiet)
ListCmd->>Executor: fetch worktrees
Executor-->>ListCmd: worktree list
alt quiet == true
ListCmd->>DisplayQuiet: display names
DisplayQuiet->>NameHelper: resolve names (per worktree)
NameHelper-->>DisplayQuiet: name
DisplayQuiet-->>ListCmd: output lines
else quiet == false
ListCmd->>DisplayRel: display table/relative paths
DisplayRel->>NameHelper: resolve names (per worktree)
NameHelper-->>DisplayRel: name
DisplayRel-->>ListCmd: output table
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
cmd/wtp/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-10-07T15:56:11.510ZApplied to files:
🧬 Code graph analysis (1)cmd/wtp/list.go (2)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cmd/wtp/list.go (1)
259-268: Consider extracting the config fallback logic.The fallback logic when
cfgis nil (lines 259-268) duplicates similar logic indisplayWorktreesRelative(lines 308-317). IfgetWorktreeNameFromPathdoesn't gracefully handle nil config, consider extracting this fallback pattern into a small helper function for DRY compliance.Example helper:
// getWorktreeDisplayName returns the display name for a worktree, with fallback for nil config func getWorktreeDisplayName(wt git.Worktree, cfg *config.Config, mainRepoPath string) string { if cfg != nil { return getWorktreeNameFromPath(wt.Path, cfg, mainRepoPath, wt.IsMain) } if wt.IsMain { return "@" } return filepath.Base(wt.Path) }Then both functions could call this helper, eliminating the duplication.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
cmd/wtp/list.go(4 hunks)cmd/wtp/list_test.go(12 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*.go: Run gofmt and goimports; keep imports grouped and organized; local import prefix follows module path github.com/satococoa/wtp
Adhere to golangci-lint rules configured for the project (vet, staticcheck, gosec, mnd, lll=120, etc.)
Errors should be wrapped with context and must not be ignored
Use snake_case for Go filenames; document exported identifiers when non-trivial
Files:
cmd/wtp/list.gocmd/wtp/list_test.go
cmd/wtp/**
📄 CodeRabbit inference engine (AGENTS.md)
cmd/wtp/**: CLI entrypoint and commands are implemented under cmd/wtp
Update CLI help text to reflect user-facing changes
Command behavior: wtp cd prints only the absolute worktree path with no side effects
Command behavior: wtp completion generates pure completion scripts via urfave/cli
Command behavior: wtp hook emits shell functions that intercept wtp cd; wtp shell-init combines completion and hook output
Files:
cmd/wtp/list.gocmd/wtp/list_test.go
**/*_test.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*_test.go: Unit tests live alongside packages and use *_test.go naming
Prefer table-driven tests and mock git operations in unit tests
Files:
cmd/wtp/list_test.go
🧠 Learnings (1)
📚 Learning: 2025-10-07T15:56:11.510Z
Learnt from: CR
PR: satococoa/wtp#0
File: AGENTS.md:0-0
Timestamp: 2025-10-07T15:56:11.510Z
Learning: Applies to cmd/wtp/completion.go : Use getWorktreeNameFromPath() to resolve worktree display names consistently across completion, errors, and parsing
Applied to files:
cmd/wtp/list.go
🧬 Code graph analysis (2)
cmd/wtp/list.go (2)
internal/config/config.go (1)
Config(12-16)internal/git/worktree.go (1)
Worktree(14-19)
cmd/wtp/list_test.go (2)
internal/command/types.go (2)
Result(11-15)Command(4-8)internal/config/config.go (2)
Config(12-16)Defaults(19-21)
🔇 Additional comments (7)
cmd/wtp/list.go (5)
55-61: LGTM! Clean flag definition.The
--quiet/-qflag is well-defined with clear usage text. The alias matches the docker convention mentioned in the PR objectives.
94-99: LGTM! Proper flag retrieval and propagation.The quiet flag is retrieved using the standard urfave/cli pattern and correctly propagated to the executor function.
103-103: LGTM! Function signature properly extended.The quiet parameter is added to support the new mode. All test callers were correctly updated to pass this parameter.
122-133: LGTM! Clean conditional logic for quiet mode.The implementation correctly:
- Prints nothing in quiet mode when no worktrees exist (scripting-friendly)
- Branches to the appropriate display function based on the quiet flag
253-272: LGTM! Well-implemented quiet mode output.The function correctly outputs worktree names one per line, which is perfect for scripting workflows like the fzf pipeline mentioned in the PR objectives. The use of
getWorktreeNameFromPathaligns with the learning about consistent worktree name resolution.cmd/wtp/list_test.go (2)
114-114: LGTM! All existing tests properly updated.All existing test calls were correctly updated to pass
falsefor the new quiet parameter, maintaining their verification of non-quiet behavior.Also applies to: 183-183, 228-228, 250-250, 311-311, 379-379, 460-460, 563-563, 705-705, 789-789
816-947: LGTM! Excellent test coverage for quiet mode.The new quiet mode tests are comprehensive and well-structured:
- Single worktree test: Verifies minimal output (
@\n) with no headers- Multiple worktrees test: Confirms one-per-line format with correct worktree names
- No worktrees test: Correctly expects empty output (not "No worktrees found" message)
- Detached HEAD test: Verifies only worktree name is shown, not branch state
These tests thoroughly validate the scripting-friendly output format described in the PR objectives.
|
Solid nit feedback from the bot, hah. I went for it. |
The --quiet / -q switch for the
listsubcommand provides scripting friendly output to the list subcommand, outputting only the values from the "PATH" column of the pre-existing output.Motivation
I took some inspiration from the
docker pssubcommand, which has a convenient and scripting-friendly -q switch stripping all non-essential information. My primary motivation for this was to make my own take on the shell scripting you provided that usesfzfto fuzzy search the branches of the worktree. My current script is a little ugly, because I parse away irrelevant output:But with this branch's changes, it could simply be
selected=$(wtp list -q | fzf --prompt="Select branch: ")LLM Disclosure
I noticed you had Claude tagged in the repository, so I'm hoping it's no imposition, but I did work on this change in Cursor with Sonnet 4.5. I reviewed and tested the code myself and happily give it my cosign.
Summary by CodeRabbit
New Features
--quiet/-qflag to the list command for simplified output: prints only worktree names one per line and suppresses output when no worktrees exist.Bug Fixes / Improvements
Tests