use clap::Subcommand;
#[derive(Subcommand)]
pub enum Commands {
Get { id: String, filter: Option<String> },
Subscribe {
id: String,
#[arg(long)]
require_modification: bool,
timeout_ms: u64,
filter: Option<String>,
},
Clear,
}
impl Commands {
pub async fn handle(self, cli_config: &crate::Config, handle: &objectiveai_cli_sdk::output::Handle) -> Result<(), crate::error::Error> {
let client = objectiveai_sdk::filesystem::Client::new(cli_config.config_base_dir.as_deref(), None::<String>, None::<String>);
match self {
Commands::Get { id, filter } => {
let content = client.read_function_execution_retry_token(&id, filter.as_deref()).await.map(objectiveai_sdk::filesystem::logs::LogContent::Json)?;
{
crate::log_line::emit_log_content(content, handle).await;
Ok(())
}
}
Commands::Subscribe { id, timeout_ms, require_modification, filter } => {
let result = client.subscribe_function_execution_retry_token(&id, std::time::Duration::from_millis(timeout_ms), require_modification, filter.as_deref()).await?;
{
match result.map(objectiveai_sdk::filesystem::logs::LogContent::Json) {
Some(content) => {
crate::log_line::emit_log_content(content, handle).await;
Ok(())
}
None => Err(crate::error::Error::LogSubscribeTimedOut),
}
}
}
Commands::Clear => {
crate::log_line::emit_log_clear_count(client.clear_function_execution_retry_tokens().await?, handle).await;
Ok(())
},
}
}
}