use clap::Args;
use std::io::{self, IsTerminal, Read};
#[derive(Args, Debug)]
pub struct RunArgs {
#[arg(value_name = "INPUT")]
pub input: Option<String>,
#[arg(long, short)]
pub name: Option<String>,
#[arg(long, short)]
pub resume: Option<String>,
#[arg(long)]
pub resume_recent: bool,
#[arg(long)]
pub model: Option<String>,
#[arg(long)]
pub max_tokens: Option<u32>,
#[arg(long)]
pub temperature: Option<f32>,
#[arg(long, default_value = "developer")]
pub role: String,
#[arg(long)]
pub max_retries: Option<u32>,
}
impl RunArgs {
pub fn to_session_args(&self) -> super::SessionArgs {
super::SessionArgs {
name: self.name.clone(),
resume: self.resume.clone(),
resume_recent: self.resume_recent,
model: self.model.clone(),
temperature: self.temperature,
max_tokens: self.max_tokens,
role: self.role.clone(),
max_retries: self.max_retries,
}
}
pub fn get_input(&self) -> Result<String, anyhow::Error> {
if let Some(input) = &self.input {
Ok(input.clone())
} else if !std::io::stdin().is_terminal() {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer)?;
let input = buffer.trim().to_string();
if input.is_empty() {
return Err(anyhow::anyhow!("No input provided via stdin"));
}
Ok(input)
} else {
Err(anyhow::anyhow!(
"No input provided. Please provide input as a parameter or pipe it via stdin."
))
}
}
}