Skip to main content

ironflow_cli/commands/
mod.rs

1//! CLI command handlers.
2
3use std::str::FromStr;
4
5pub mod api_key;
6pub mod audit_log;
7pub mod logs;
8pub mod run;
9pub mod secret;
10pub mod stats;
11pub mod template;
12pub mod user;
13pub mod workflow;
14
15/// Parse a CLI value into one of the SDK's generated enums.
16///
17/// The generated `FromStr` error carries no information, so it is replaced by a
18/// message that tells the caller what to type instead. The generated enums
19/// expose no variant iterator, hence `accepted` being passed in.
20///
21/// # Errors
22///
23/// Returns the list of accepted values when `raw` is not one of them.
24pub(crate) fn parse_enum<T: FromStr + ToString>(
25    raw: &str,
26    accepted: &[T],
27    noun: &str,
28) -> Result<T, String> {
29    T::from_str(raw).map_err(|_| {
30        let accepted: Vec<String> = accepted.iter().map(ToString::to_string).collect();
31        format!("unknown {noun} '{raw}'; accepted: {}", accepted.join(", "))
32    })
33}