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