feat: accept a search query as a command-line argument#205
Merged
Conversation
Treat a leading non-flag, non-subcommand token (or several) as an initial search query so `dispatch auth` or `dispatch fix auth bug` opens the TUI with the search box pre-filled and the list filtered. The query seeds the same search state as typing it interactively: quick search runs immediately with a deep search scheduled to follow. Closes #198 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lets you pass a search term on the command line so
dispatch authopens the TUI with the search box already filled in and the list filtered to matches.Today any non-flag token errors out with
unknown flag: auth. To search you have to start the TUI, press/, and type. When you already know what you are looking for, passing it on the command line skips those steps and pairs well with shell history and aliases.How
cmd/dispatch/cli.go:handleArgsnow collects leading non-flag, non-subcommand tokens and joins them into a query, returned as a new value. Known subcommands (help,version,update,completion,doctor) and unknown flags (leading-) keep their current behavior.cmd/dispatch/main.go: passes the query to the newtui.NewModelWithQuery, and documentsdispatch [query]in the usage text.internal/tui/model.go:NewModelWithQueryseeds aninitialQueryfield;applyInitialQueryputs the model into the same search state as interactive typing (search bar focused and populated, tokens parsed, quick search now, deep search scheduled).internal/tui/handlers.go:handleStoreOpenedapplies the initial query once, before building the first load command, so the first render is already filtered, then clears it.Multiple tokens join with spaces, so
dispatch fix auth bugsearches forfix auth bug. Clearing withescbehaves exactly like an interactively typed query.Testing
go build ./...go vet ./...gofumpt -l .(clean)golangci-lint run --timeout 15m(0 issues)go test ./... -count=1(all packages pass)New tests cover argument parsing (single query, multi-word query, subcommands not shadowed, unknown flags still error) in
cmd/dispatch/cli_test.go, and that the initial query reaches the model state and is applied on store open ininternal/tui/model_search_test.go.Closes #198