Skip to main content

ironflow_cli/commands/
mod.rs

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