pub mod create;
pub mod tail;
use std::path::PathBuf;
use clap::Subcommand;
use crate::error::CliError;
use crate::output::{OutputFormat, OutputSpec};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormatArg {
Text,
Jsonl,
}
pub fn resolve_format(fmt: OutputFormat) -> Result<FormatArg, CliError> {
match fmt {
OutputFormat::Text => Ok(FormatArg::Text),
OutputFormat::Jsonl => Ok(FormatArg::Jsonl),
OutputFormat::Json => Err(CliError::user(
"unsupported_format",
"streaming verbs do not support --output json (pretty single-document); use jsonl or text",
)),
}
}
#[derive(Subcommand, Debug)]
pub enum EventAction {
Tail {
run_id: String,
#[arg(long, default_value_t = 0)]
from_seq: u64,
#[arg(long)]
follow: bool,
#[arg(long)]
to_file: Option<std::path::PathBuf>,
},
Create {
run_id: String,
#[arg(long)]
kind: String,
#[arg(long)]
node_id: Option<String>,
#[arg(long)]
from_file: PathBuf,
#[arg(long)]
idempotency_key: Option<String>,
#[arg(long)]
dry_run: bool,
},
}
pub fn dispatch(
action: EventAction,
spec: &OutputSpec,
warnings: &[String],
) -> Result<(), CliError> {
match action {
EventAction::Tail {
run_id,
from_seq,
follow,
to_file,
} => tail::run(tail::Args {
run_id,
from_seq,
follow,
to_file,
spec,
warnings,
}),
EventAction::Create {
run_id,
kind,
node_id,
from_file,
idempotency_key,
dry_run,
} => create::run(create::Args {
run_id,
kind,
node_id,
from_file,
idempotency_key,
dry_run,
spec,
warnings,
}),
}
}