Skip to content
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

feat: support stdin and text input in cli #335

Merged
merged 3 commits into from
Nov 26, 2024
Merged

Conversation

wendytang
Copy link
Collaborator

@wendytang wendytang commented Nov 25, 2024

Support pipes and/or text input. Usage:

echo "say whats for dinner in japanese" | cargo run --bin goose -- run
image
cargo run --bin goose -- run -t "say hello in japanese"  
image

@wendytang wendytang changed the title stdin feat: support stdin for cli Nov 25, 2024
@wendytang wendytang changed the title feat: support stdin for cli feat: support stdin and text input in cli Nov 25, 2024
@wendytang wendytang marked this pull request as ready for review November 25, 2024 21:43
let mut stdin = String::new();
io::stdin()
.read_to_string(&mut stdin)
.expect("Failed to read from stdin");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this works great when used in a pipe, but if someone does not use a pipe, pass --text or pass --instructions, then it sites there reading input until you hit CTRL-D or CTRL-C which is confusing.

Is there a way to detect not piping and error maybe?

This is also how old goose worked in the same setting, so maybe we can skip solving this for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it sounds easy, but i think the way to do it would be to spawn a thread and then poll the channel. I'll skip this for now.

https://stackoverflow.com/questions/30012995/how-can-i-read-non-blocking-from-stdin

@wendytang wendytang force-pushed the wtang/support_run_pipe branch from dff8dd3 to ee3f61f Compare November 26, 2024 18:49
@wendytang wendytang merged commit 8e7506d into v1.0 Nov 26, 2024
2 checks passed
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.

3 participants