Add --print flag for non-interactive stdout output#59
Open
DavidTeju wants to merge 1 commit intosamtay:mainfrom
Open
Add --print flag for non-interactive stdout output#59DavidTeju wants to merge 1 commit intosamtay:mainfrom
DavidTeju wants to merge 1 commit intosamtay:mainfrom
Conversation
Add -p/--print flag that prints the top answer to stdout and exits immediately, without a spinner, keypress prompt, or TUI. This makes so fully pipeable and usable from scripts and non-TTY environments. --print implies --lucky (fetches the top answer).
638865e to
ecbec54
Compare
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.
Summary
Add
-p/--printflag that prints the top answer to stdout and exits immediately — no spinner, no keypress prompt, no TUI. This makessofully pipeable and usable from scripts, CI, and non-TTY environments (e.g., AI agents, editor plugins).Motivation
The
--luckyflag already fetches the top answer, but it requires a TTY because:crossterm::terminal::enable_raw_mode()Term::wait_for_key()blocks for interactive inputThis means
so --lucky "query" | headfails withCrossterm error: Device not configured (os error 6). The--printflag fixes this by bypassing both the spinner and the interactive prompt.Usage
--printimplies--lucky(it always fetches the top-voted answer).Changes
src/cli.rs-p/--printflag, force lucky mode when print is setsrc/main.rsprintcode path: search without spinner, print answer, exitTest plan
cargo test— all 26 tests passso --print -e startpage "how to exit vim"— prints answer, exits cleanlyso -p -e stackexchange "python list comprehension"— works with short flagso -p "query" | head— pipes correctly, no TTY errorso --lucky "query"— still works as before (regression)