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