Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use goose_cli::commands::session::handle_session_list;
use goose_cli::logging::setup_logging;
use goose_cli::session;
use goose_cli::session::build_session;
use std::io::{self, Read};
use std::io::Read;
use std::path::PathBuf;

#[derive(Parser)]
Expand Down Expand Up @@ -147,7 +147,7 @@ enum Command {
short,
long,
value_name = "FILE",
help = "Path to instruction file containing commands",
help = "Path to instruction file containing commands. Use - for stdin.",
conflicts_with = "input_text"
)]
instructions: Option<String>,
Expand Down Expand Up @@ -360,24 +360,28 @@ async fn main() -> Result<()> {
extension,
builtin,
}) => {
// Validate that we have some input source
if instructions.is_none() && input_text.is_none() {
eprintln!("Error: Must provide either --instructions or --text");
std::process::exit(1);
}

let contents = if let Some(file_name) = instructions {
let file_path = std::path::Path::new(&file_name);
std::fs::read_to_string(file_path).expect("Failed to read the instruction file")
} else if let Some(input_text) = input_text {
input_text
} else {
let mut stdin = String::new();
io::stdin()
.read_to_string(&mut stdin)
.expect("Failed to read from stdin");
stdin
let contents = match (instructions, input_text) {
(Some(file), _) if file == "-" => {
let mut stdin = String::new();
std::io::stdin()
.read_to_string(&mut stdin)
.expect("Failed to read from stdin");
stdin
}
(Some(file), _) => std::fs::read_to_string(&file).unwrap_or_else(|err| {
eprintln!(
"Instruction file not found — did you mean to use goose run --text?\n{}",
err
);
std::process::exit(1);
}),
(None, Some(text)) => text,
(None, None) => {
eprintln!("Error: Must provide either --instructions (-i) or --text (-t). Use -i - for stdin.");
std::process::exit(1);
}
};

let mut session = build_session(
identifier.map(extract_identifier),
resume,
Expand All @@ -386,6 +390,7 @@ async fn main() -> Result<()> {
debug,
)
.await;

setup_logging(
session.session_file().file_stem().and_then(|s| s.to_str()),
None,
Expand All @@ -396,6 +401,7 @@ async fn main() -> Result<()> {
} else {
session.headless(contents).await?;
}

return Ok(());
}
Some(Command::Agents(cmd)) => {
Expand Down
Loading