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